Increase pagination number

karim-synergy

Jan 9th, 2018 11:13 AM

Hi everyone, i have a problem when try to change pagination number of server side.

Actually its on 15 per page but i want to show over 50 records for page. ¿Where can I define that variable?

Regards.

tnylea

Jan 11th, 2018 01:47 AM

Hey karim-synergy,

Can you let me know which product your are referring to and I can help out with the answer.

Thanks!

karim-synergy

Jan 11th, 2018 06:09 AM

Hi tnylea, usually in laravel you can set pagination in that way

$users = DB::table('users')->paginate(15);
	

But in voyager's bread controller i cant see how is define that number to paginate data. only pass $getter variable with "paginate" or "get" data.

Controller

public function index(Request $request) { // GET THE SLUG, ex. 'posts', 'pages', etc. $slug = $this->getSlug($request);

    // GET THE DataType based on the slug
    $dataType = Voyager::model('DataType')->where('slug', '=', $slug)->first();

    // Check permission
    $this->authorize('browse', app($dataType->model_name));

    $getter = $dataType->server_side ? 'paginate' : 'get';

    $search = (object) ['value' => $request->get('s'), 'key' => $request->get('key'), 'filter' => $request->get('filter')];
    $searchable = $dataType->server_side ? array_keys(SchemaManager::describeTable(app($dataType->model_name)->getTable())->toArray()) : '';
    $orderBy = $request->get('order_by');
    $sortOrder = $request->get('sort_order', null);

    // Next Get or Paginate the actual content from the MODEL that corresponds to the slug DataType
    if (strlen($dataType->model_name) != 0) {
        $model = app($dataType->model_name);
        $query = $model::select('*');

        $relationships = $this->getRelationships($dataType);

        // If a column has a relationship associated with it, we do not want to show that field
        $this->removeRelationshipField($dataType, 'browse');

        if ($search->value && $search->key && $search->filter) {
            $search_filter = ($search->filter == 'equals') ? '=' : 'LIKE';
            $search_value = ($search->filter == 'equals') ? $search->value : '%'.$search->value.'%';
            $query->where($search->key, $search_filter, $search_value);
        }

        if ($orderBy && in_array($orderBy, $dataType->fields())) {
            $querySortOrder = (!empty($sortOrder)) ? $sortOrder : 'DESC';
            $dataTypeContent = call_user_func([
                $query->with($relationships)->orderBy($orderBy, $querySortOrder),
                $getter,
            ]);
        } elseif ($model->timestamps) {
            $dataTypeContent = call_user_func([$query->latest($model::CREATED_AT), $getter]);
        } else {
            $dataTypeContent = call_user_func([$query->with($relationships)->orderBy($model->getKeyName(), 'DESC'), $getter]);
        }

        // Replace relationships' keys for labels and create READ links if a slug is provided.
        $dataTypeContent = $this->resolveRelations($dataTypeContent, $dataType);
    } else {
        // If Model doesn't exist, get data from table name
        $dataTypeContent = call_user_func([DB::table($dataType->name), $getter]);
        $model = false;
    }

    // Check if BREAD is Translatable
    if (($isModelTranslatable = is_bread_translatable($model))) {
        $dataTypeContent->load('translations');
    }

    // Check if server side pagination is enabled
    $isServerSide = isset($dataType->server_side) && $dataType->server_side;

    $view = 'voyager::bread.browse';

    if (view()->exists("voyager::$slug.browse")) {
        $view = "voyager::$slug.browse";
    }

    return Voyager::view($view, compact(
        'dataType',
        'dataTypeContent',
        'isModelTranslatable',
        'search',
        'orderBy',
        'sortOrder',
        'searchable',
        'isServerSide'
    ));
}
	
	
	Regards.
devdojo

Jan 17th, 2018 01:46 AM

That's a pretty good question :P I'm going to have to do some investigating. I'll keep you posted.

mark-co

Apr 12th, 2019 10:37 AM

Hi! Any updates on this?

UPDATE:

If you don't turn the server side pagination on, Voyager by default will make use of data tables (https://datatables.net/). To increase the number of displayed entries on the browse page for your BREAD, you can set this on voyager's config file under the dashboard. Create a 'data_tables' configuration having the key 'pageLength' that you set to your desired number (https://datatables.net/reference/option/pageLength).

'dashboard' => [
    // Add custom list items to navbar's dropdown
    'navbar_items' => [
        'Profile' => [
            'route'      => 'voyager.profile',
            'classes'    => 'class-full-of-rum',
            'icon_class' => 'voyager-person',
        ],
        'Home' => [
            'route'        => '/',
            'icon_class'   => 'voyager-home',
            'target_blank' => true,
        ],
        'Logout' => [
            'route'      => 'voyager.logout',
            'icon_class' => 'voyager-power',
        ],
    ],

    'data_tables' => [
        "pageLength" => 100,
    ],

    'widgets' => [
        'TCG\\Voyager\\Widgets\\UserDimmer',
        'TCG\\Voyager\\Widgets\\PostDimmer',
        'TCG\\Voyager\\Widgets\\PageDimmer',
    ],

],
carbajal-tomlin

Jan 7th, 2020 09:01 AM

This pagination not work for mysqli connection , i want a pagination with dropdown record search with mysqli .please reply as soon as possible Prepaid Gift Balance