Skip to main content
Version: 2.0.1

Documentation

Initialization

<?php
use Irsyadulibad\DataTables\DataTables;

DataTables::use('table');
?>

Available Methods

The following methods are available to be used in this library

Select Table

Select the table that you want to use

DataTables::use('table')

Set Output

The default parameter is false, which is automatically return the JSON data. You can return the data's dump by passing the true param

DataTables::use('table')
->make(true);

Select Fields

Select the sepicifics column in the table

->select('username, password')

Where Clause

->where(['role' => 'user', 'active' => 1])

orWhere Clause

->orWhere(['role' => 'user', 'active' => 0])

Join Clause

// <table>, <condition>, <type>
->join('address', 'users.id = address.uid', 'INNER JOIN')

Column editing

You can edit columns before output on json

Add Column

Add custom column which is not in the table

// <name>, <callback>
->addColumn('action', function($data) {
return '<a href="/edit/'.$data->id.'">edit</a>';
})

Edit Column

// <name>, <callback>
->editColumn('created_at', function($data) {
return format($data->created_at);
})

Raw Columns

By default, all of the data is escaped to prevent XSS. But if you want to unescape them, you can use this method

->rawColumns(['bio'])

Hide Columns

Hide columns from JSON output

->hideColumns(['password'])