Skip to main content
Version: 2.1.0

Introduction

CI4-DataTables is a datatables library that will speed up you to create serverside datatable API using the CodeIgniter v4 framework.

This is an example code for using this library:

PHP:

<?php namespace App\Controllers;

use Irsyadulibad\DataTables\DataTables;

class Home extends BaseController
{
public function json()
{
return DataTables::use('users')
->where(['role' => 'admin'])
->hideColumns(['password'])
->rawColumns(['bio'])
->make(true);

// Or with helper (recommended)
return datatables('users')->make();
}
}

JavaScript:

$('#table').DataTable({
processing: true,
serverSide: true,
ajax:{
url: 'http://localhost:8080/json'
},
columns: [
{data: 'username', name: 'username'},
{data: 'email', name: 'email'},
{data: 'fullname', name: 'fullname'}
{data: 'bio', name: 'bio'}
]
});