This is an extension for CodeIgniter 4.2.x to add Datatables support to your application.
The purpose is to generate the html table and the javascript function for its management with a few lines of code.
It is possible to define a model to be passed as a dependency in the constructor; this model will be used for the management of columns and queries.
$userModel = new \atsanna\Models\UserModel();
$table = new \atsanna\DataTables\Html\Table( $userModel );
There are many configuration possibilities:
- Enable or disable automatic calculation of column width
- Enable or disable deferred rendering for faster initialization speed
- Enable or disable the table information display field
- Enable or disable column sorting
- Enable or disable table pagination
- Layout button display options
- Enable or disable the display of a 'processing' indicator
- Enable horizontal scrolling
- Enable vertical scrolling
- Allow the table to shrink in height when a limited number of rows are displayed
- Ability to search (filter) feature control
- Enable or disable server side processing
- Enable or disable state saving
- Change the options in the page length selection list
- Set column specific initialization properties
The default configuration can be customized as follows:
$table->getConfiguration()
->setPaging(true)
->setPagingType( 'full_numbers')
->setOrdering(true)
->setInfo(false)
->setSearching(true)
->setLengthMenu('[[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]]')
->setAutoWidth(false)
->setScrollX(true);
It is possible to customize the rendering:
$data = [
'id' => $userModel->table,
'class' => 'table table-striped table-bordered',
'style' => 'width: 100%; margin-left: auto; margin-right: auto;',
'fields' => $userModel->allowedFields,
];
echo $table->render($data);