nerweb / laravel-tblist
Simple admin table listing for bootstrap 3 and laravel 4|5
Requires
- php: >=5.3.0
- illuminate/support: 4.x|5.0.x
Requires (Dev)
- phpunit/phpunit: 4.0.*
This package is not auto-updated.
Last update: 2022-02-01 12:40:17 UTC
README
Simple admin table listing for bootstrap 3 and laravel 4|5
Installation
Add the following to your composer.json
file:
"nerweb/laravel-tblist": "1.2.x"
Then, run composer update nerweb/laravel-tblist
or composer install
if you have not already installed packages.
and
Publish assets:
php artisan asset:publish nerweb/laravel-tblist
Simple Example
First, create a class name UserTblist
.
use Nerweb\Tblist\BaseTblist; class UserTblist extends BaseTblist { // set no result message public $noResults = "No User found."; function __construct() { $this->table = 'users'; $this->setQuery(); $this->setColumns(); } protected function setQuery() { $this->query = User::where('active',1); $this->columnsToSelect = array('*'); } protected function setColumns() { $this->addCheckableColumn(); $this->columns['username'] = array( 'label' => 'Username', 'sortable' => true, 'table_column' => 'users.username', ); $this->columns['email'] = array( 'label' => 'Email', 'sortable' => true, 'classes' => 'someclass someclass2', 'table_column' => 'users.email', 'thead_attr' => 'style="width:200px" data-someattr="example"', ); $this->addActionColumn(); } }
Create a route and and its controller. insert below inside the controller method.
$list = new UserTblist(); $list->prepareList(); return View::make('users.index', array('list', $list));
Create the blade user/index.blade.php
and insert below.
{{ Form:open(array( 'action' => $list->getBaseURL(), 'method' =>'get', 'id' =>'user_tblist', 'class' =>'tblist-form' )) }} {{ $list->getTableData() }} {{ $list->getPagination() }} {{ $list->getPaginationInfo() }} {{ Form::close() }}
For complete example, see example
folder.
API Reference
Note! Child class should always extend Nerweb\Tblist\BaseTblist
.
Column
The column
property accepts a data for column name as a key and column options as a value.
Column key
The column key
may or may not exists in the result row. Column key also assumes
as the name to be sorted.
Note! if column key
doesn't exists in the result row, you should create a protected method colSetTheColumnName
as custom column.
Column options
Options | type | Description |
---|---|---|
label |
string |
Column header label. |
sortable |
bool |
Whether sortable or not. |
table_column |
string |
if set, then use its value instead of the column key as the column name to sort (i.e roles.admin , users.admin ). |
classes |
string |
table column classes. Note! Both applied to header, footer and body column. |
thead_attr |
string |
Table header attribute. |
Note! All column option
is default to null
.
Custom Column Display
Add protected method colSetColumnNameToCamel
(i.e colSetUsername
, colSetCreatedAt
) that only accepts 1 parameter an object of result row. Then echo or display the string.
Example
in your class, UserTblist
for this example. Add this next to setColumns
method
protected function colSetUsername($row) { echo Html::link("/users/{$row->id}/view", $row->username); }
Custom Column
Sometimes we want to show column that is not in the result object row.
To do this, add a column key
to columns
property and make sure that the sortable
options is set to false
.
and
create a method called colSetYourColumnName($row)
that accepts result row.
Multiple Tblist
Sometimes we want to display multiple table listing on the same page.
To do this,
- on class initialization, in this case
$list = new UserTblist()
. Override base URL via$list->setBaseURL($url, $parameters)
method. - set the tblist form action with
$list->getBaseURL()
. - create the route with controller and return the json data of the tblist.
Demo
see simple demo here
License
This project is open-sourced software licensed under the MIT license.