Skip to content

Commit a5cecf4

Browse files
authored
Merge pull request #69 from leantony/2.0
add docs for templating
2 parents cf05fe5 + 5a0a0a0 commit a5cecf4

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

docs/customization.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ These will be copied to `resources/views/vendor/leantony/grid`. From there, you
178178
# Advanced customization
179179
Most of the grid's functionality in terms of manipulating columns, exporting, buttons, filters, is customizable, and for that which is not, am working on it. However, you should be able to;
180180
+ [Buttons](buttons.md)
181+
+ [Templating](templating.md)
181182
+ [Columns, rows, search, export and filters](general.md)
182183
+ [Modal forms](modals.md)
183184
+ [Pagination](pagination.md)

docs/templating.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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

Comments
 (0)