Skip to content

đŸ”¥Datatables support for CodeIgniter 4

License

Notifications You must be signed in to change notification settings

atsanna/codeigniter4-datatables

Folders and files

NameName
Last commit message
Last commit date
Mar 18, 2024
Mar 18, 2024
Mar 18, 2024
Mar 18, 2024
Mar 15, 2024
Mar 15, 2024
Jun 10, 2022
Jun 10, 2022
Mar 18, 2024
Oct 17, 2023
Jun 6, 2022
Mar 18, 2024
Jun 6, 2022
Jun 10, 2022
Mar 18, 2024
Jun 8, 2022
Mar 18, 2024
Jun 10, 2022
Jun 10, 2022

Repository files navigation

codeigniter4-datatables

CodeIgniter 4.2.x Unit Tests Static Analysis Architecture Coverage Status GitHub license contributions welcome

This is an extension for CodeIgniter 4.2.x to add Datatables support to your application.

Warning: this is a non-functional experimental version!

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);

See the documentation

Documentation