|
| 1 | +The grid supports custom layouts/templates, since it uses a layout to control how the grid's |
| 2 | +container looks like. |
| 3 | + |
| 4 | +# Explanation |
| 5 | +The default layout is a bootstrap 4 card element. Looks like this; |
| 6 | +```php |
| 7 | +<div class="row laravel-grid" id="{{ $grid->getId() }}"> |
| 8 | + <div class="col-md-12 col-xs-12 col-sm-12"> |
| 9 | + <div class="card"> |
| 10 | + <div class="card-header"> |
| 11 | + <div class="pull-left"> |
| 12 | + <h4 class="grid-title">{{ $grid->renderTitle() }}</h4> |
| 13 | + </div> |
| 14 | + {!! $grid->renderPaginationInfoAtHeader() !!} |
| 15 | + </div> |
| 16 | + <div class="card-body"> |
| 17 | + @yield('data') |
| 18 | + </div> |
| 19 | + <div class="card-footer"> |
| 20 | + {!! $grid->renderPaginationInfoAtFooter() !!} |
| 21 | + {!! $grid->renderPaginationLinksSection() !!} |
| 22 | + </div> |
| 23 | + </div> |
| 24 | + </div> |
| 25 | +</div> |
| 26 | +``` |
| 27 | +The `@yield('data')` section will ensure that the grid's content is put in the view that extends this layout |
| 28 | + |
| 29 | +# Important variables |
| 30 | ++ `laravel-grid` => Required to allow the grid's default CSS apply styling to the buttons, etc. |
| 31 | ++ `$grid->getId()` => Required to set a PJAX container for the grid. Otherwise, PJAX won't work |
| 32 | ++ `$grid->renderTitle()` => If you need the grid's title displayed |
| 33 | ++ `$grid->renderPaginationInfoAtHeader()` => Required to display sth like `Displaying 1 to 10 of x records` on your grid |
| 34 | ++ `$grid->renderPaginationInfoAtFooter()` => Required to display same text as the header pagination, but pushed towards the left so that pagination links can be accommodated |
| 35 | ++ `$grid->renderPaginationLinksSection()` => Required to display pagination links |
| 36 | + |
| 37 | +# How to use |
| 38 | +The grid's configuration allows you to change the grid's template to your own custom built one. However, this will apply to all grid's you create. |
| 39 | +```php |
| 40 | +/** |
| 41 | + * Grid templates |
| 42 | + */ |
| 43 | + 'templates' => [ |
| 44 | + /** |
| 45 | + * The view to use for the templates |
| 46 | + */ |
| 47 | + 'view' => 'leantony::grid.templates.bs4-card' |
| 48 | + ] |
| 49 | +``` |
| 50 | +If you need per grid customization of the above, you can call the `withCustomTemplate` function when creating your grid. Like this; |
| 51 | +```php |
| 52 | +$someGrid->create(['query' => User::query(), 'request' => $request])->withCustomTemplate('view_name') |
| 53 | +``` |
| 54 | + |
| 55 | +# Previous |
| 56 | +[Customization](customization.md) |
0 commit comments