Skip to content

Commit

Permalink
Merge pull request #69 from leantony/2.0
Browse files Browse the repository at this point in the history
add docs for templating
  • Loading branch information
leantony authored Jun 23, 2018
2 parents cf05fe5 + 5a0a0a0 commit a5cecf4
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ These will be copied to `resources/views/vendor/leantony/grid`. From there, you
# Advanced customization
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;
+ [Buttons](buttons.md)
+ [Templating](templating.md)
+ [Columns, rows, search, export and filters](general.md)
+ [Modal forms](modals.md)
+ [Pagination](pagination.md)
Expand Down
56 changes: 56 additions & 0 deletions docs/templating.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
The grid supports custom layouts/templates, since it uses a layout to control how the grid's
container looks like.

# Explanation
The default layout is a bootstrap 4 card element. Looks like this;
```php
<div class="row laravel-grid" id="{{ $grid->getId() }}">
<div class="col-md-12 col-xs-12 col-sm-12">
<div class="card">
<div class="card-header">
<div class="pull-left">
<h4 class="grid-title">{{ $grid->renderTitle() }}</h4>
</div>
{!! $grid->renderPaginationInfoAtHeader() !!}
</div>
<div class="card-body">
@yield('data')
</div>
<div class="card-footer">
{!! $grid->renderPaginationInfoAtFooter() !!}
{!! $grid->renderPaginationLinksSection() !!}
</div>
</div>
</div>
</div>
```
The `@yield('data')` section will ensure that the grid's content is put in the view that extends this layout

# Important variables
+ `laravel-grid` => Required to allow the grid's default CSS apply styling to the buttons, etc.
+ `$grid->getId()` => Required to set a PJAX container for the grid. Otherwise, PJAX won't work
+ `$grid->renderTitle()` => If you need the grid's title displayed
+ `$grid->renderPaginationInfoAtHeader()` => Required to display sth like `Displaying 1 to 10 of x records` on your grid
+ `$grid->renderPaginationInfoAtFooter()` => Required to display same text as the header pagination, but pushed towards the left so that pagination links can be accommodated
+ `$grid->renderPaginationLinksSection()` => Required to display pagination links

# How to use
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.
```php
/**
* Grid templates
*/
'templates' => [
/**
* The view to use for the templates
*/
'view' => 'leantony::grid.templates.bs4-card'
]
```
If you need per grid customization of the above, you can call the `withCustomTemplate` function when creating your grid. Like this;
```php
$someGrid->create(['query' => User::query(), 'request' => $request])->withCustomTemplate('view_name')
```

# Previous
[Customization](customization.md)

0 comments on commit a5cecf4

Please sign in to comment.