DataTables server-side for CodeIgniter, supported both for CodeIgniter 3 and CodeIgniter 4.

Overview

CodeIgniter DataTables

DataTables server-side for CodeIgniter, supported both for CodeIgniter 3 and CodeIgniter 4.

Note: This library only handle the server-side part, you still needs to configure the client side like jQuery, DataTables library and including the styles.

Requirements

If you are using CodeIgniter, you can use this library with no extra requirement.

Installation

You just need to use composer and everything is done.

composer require ngekoding/codeigniter-datatables

Usage

Here is the basic example to use this library, you are freely make any changes for the client side, like defining searchable column, orderable column, etc...

CodeIgniter 3 Example

// CodeIgniter 3 Example

// Here we will select all fields from posts table
// and make a join with categories table
// Please note: we don't need to call ->get() here
$queryBuilder = $this->db->select('p.*, c.name category')
                    ->from('posts p')
                    ->join('categories c', 'c.id=p.category_id');

/**
 * The first parameter is the query builder instance
 * and the second is the codeigniter version (3 or 4) 
 */
$datatables = new Ngekoding\CodeIgniterDataTables\DataTables($queryBuilder, '3');
$datatables->generate(); // done

CodeIgniter 4 Example

// CodeIgniter 4 Example

$db = db_connect();
$queryBuilder = $db->from('posts p')
                   ->select('p.*, c.name category')
                   ->join('categories c', 'c.id=p.category_id');

$datatables = new Ngekoding\CodeIgniterDataTables\DataTables($queryBuilder, '4');
$datatables->generate(); // done

The above examples will give you for ajax data source (arrays), so you need to make sure the table header you makes for the client side is match with the ajax response. We will talk about the objects data source below.

Client Side Examples

You must include the jQuery and DataTables library.

<link href="https://cdn.datatables.net/1.11.5/css/jquery.dataTables.min.css" rel="stylesheet">

<table id="table-post" class="display" width="100%">
  <thead>
    <th>ID</th>
    <th>Title</th>
    <th>Category</th>
    <th>Description</th>
  </thead>
</table>

<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script src="https://cdn.datatables.net/1.11.5/js/jquery.dataTables.min.js"></script>
<script>
$('#table-post').DataTable({
  processing: true,
  serverSide: true,
  ajax: {
    url: 'http://localhost/project/index.php/post/ajax_datatables', // Change with your own
    method: 'GET', // You are freely to use POST or GET
  }
})
</script>

Objects Data Source

As was mentioned above, the default data source we get is an arrays. It is easy also to get the objects data source.

To get objects response, you just need to call asObject() method.

$datatables->asObject()
           ->generate();

And then you can configure the client side with columns option to fit your data.

$('#table-post').DataTable({
  processing: true,
  serverSide: true,
  ajax: {
    url: 'http://localhost/project/index.php/post/ajax_datatables',
    method: 'GET',
  },
  columns: [
    { data: 'id' },
    { data: 'title' },
    { data: 'category' },
    { data: 'description' }
  ]
})
</script>

Some Others Settings

Some basic functionalities already available, here is the full settings you can doing to this library.

Use class for spesify the CodeIgniter version

// General, use the second param to define the version
// The default is 4
$datatables = new Ngekoding\CodeIgniterDataTables\DataTables($queryBuilder, '3');

// CodeIgniter 3
$datatables = new Ngekoding\CodeIgniterDataTables\DataTablesCodeIgniter3($queryBuilder);

// CodeIgniter 4
$datatables = new Ngekoding\CodeIgniterDataTables\DataTablesCodeIgniter4($queryBuilder);

Available Options

$datatables = new Ngekoding\CodeIgniterDataTables\DataTables($queryBuilder);

// Return the output as objects instead of arrays
$datatables->asObject();

// Only return title & category (accept string or array)
$datatables->only(['title', 'category']);

// Return all except the id
// You may use one of only or except
$datatables->except(['id']);

// Format the output
$datatables->format('title', function($value, $row) {
  return '<b>'.$value.'</b>';
});

// Add extra column
$datatables->addColumn('action', function($row) {
  return '<a href="url/to/delete/post/'.$row->id.'">Delete</a>';
});

// Add squence number
// The default key is `sequenceNumber`
// You can change it with give the param
$datatables->addSequenceNumber();
$datatables->addSequenceNumber('rowNumber'); // It will be rowNumber

// Don't forget ot call generate to get the results
$datatables->generate();

Another Example

I already use this library to the existing project with completed CRUD operations, you can found it here.

Please look at these files:

  • application/composer.json
  • application/controllers/Post.php
  • application/models/M_post.php
  • application/views/template.php
  • application/views/posts/index-datatables.php
  • application/helpers/api_helper.php
  • assets/js/custom.js
You might also like...
⚡ PowerGrid generates Advanced Datatables using Laravel Livewire.
⚡ PowerGrid generates Advanced Datatables using Laravel Livewire.

📚 Documentation | 🔥 Features | ⌨️ Get started Livewire ⚡ PowerGrid ⚡ PowerGrid creates modern, powerful and easy to customize Datatables based on La

Laravel-FCM is an easy to use package working with both Laravel and Lumen for sending push notification with Firebase Cloud Messaging (FCM).

Laravel-FCM Introduction Laravel-FCM is an easy to use package working with both Laravel and Lumen for sending push notification with Firebase Cloud M

Jetstrap is a lightweight laravel 8 package that focuses on the VIEW side of Jetstream / Breeze package installed in your Laravel application

A Laravel 8 package to easily switch TailwindCSS resources generated by Laravel Jetstream and Breeze to Bootstrap 4.

The University of Arizona Libraries will no longer provide support for Guide on the Side.

The University of Arizona Libraries will no longer provide support for Guide on the Side. The code will remain openly available; however, UAL can no longer provide code fixes or upgrades.

Textpattern-jquery-ui-theme - The jQuery UI theme used within the Textpattern CMS admin-side.

Textpattern jQuery UI theme The jQuery UI theme used within the Textpattern CMS admin-side. Supported web browsers Chrome, Edge, Firefox, Safari and O

Symfony bundle that provides Cross Site Request Forgery (CSRF or XSRF) protection for client-side applications

CSRF Cookie Bundle This Symfony bundle provides Cross Site Request Forgery (CSRF or XSRF) protection for client-side applications requesting endpoints

Loja virtual fictícia para compra de produtos e estilização dos mesmos. Desenvolvido com as tecnologias: HTML, CSS, PHP, CODEIGNITER, JavaScript, Bootstrap e Mysql.
Loja virtual fictícia para compra de produtos e estilização dos mesmos. Desenvolvido com as tecnologias: HTML, CSS, PHP, CODEIGNITER, JavaScript, Bootstrap e Mysql.

StampGeek Loja virtual fictícia para compra de produtos e estilização dos mesmos. Desenvolvido com as tecnologias: HTML, CSS, PHP, CODEIGNITER, JavaSc

Boilerplate code for protecting a form with proof of work. Uses javascript in the browser to generate the hashcash and PHP on the server to generate the puzzle and validate the proof of work.

Boilerplate code for protecting a form with proof of work. Uses javascript in the browser to generate the hashcash and PHP on the server to generate the puzzle and validate the proof of work.

This is a plugin written in the PHP programming language and running on the PocketMine platform that works stably on the API 3.25.0 platform. It helps to liven up your server with Tags!
This is a plugin written in the PHP programming language and running on the PocketMine platform that works stably on the API 3.25.0 platform. It helps to liven up your server with Tags!

General This is a plugin written in the PHP programming language and running on the PocketMine platform that works stably on the API 3.25.0 platform.

Comments
  • Problem in Php 8.1.5

    Problem in Php 8.1.5

    I don't know why this error is comming. It was working fine in PHP 7.3 version. But when I update my PHP version to 8.1.5 then it's giving me this error. Any solution?

    A PHP Error was encountered
    Severity: 8192
    
    Message: Return type of Symfony\Component\HttpFoundation\ParameterBag::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
    
    Filename: http-foundation/ParameterBag.php
    
    Line Number: 220
    
    Backtrace:
    
    File: C:\xampp\htdocs\projects\codeigniter\fastpay-payment-gateway\fastpay\vendor\symfony\http-foundation\ParameterBag.php
    Line: 19
    Function: _error_handler
    
    File: C:\xampp\htdocs\projects\codeigniter\fastpay-payment-gateway\fastpay\vendor\composer\ClassLoader.php
    Line: 571
    Function: include
    
    File: C:\xampp\htdocs\projects\codeigniter\fastpay-payment-gateway\fastpay\vendor\composer\ClassLoader.php
    Line: 428
    Function: Composer\Autoload\includeFile
    
    File: C:\xampp\htdocs\projects\codeigniter\fastpay-payment-gateway\fastpay\vendor\symfony\http-foundation\Request.php
    Line: 273
    Function: loadClass
    
    File: C:\xampp\htdocs\projects\codeigniter\fastpay-payment-gateway\fastpay\vendor\symfony\http-foundation\Request.php
    Line: 255
    Function: initialize
    
    File: C:\xampp\htdocs\projects\codeigniter\fastpay-payment-gateway\fastpay\vendor\symfony\http-foundation\Request.php
    Line: 2095
    Function: __construct
    
    File: C:\xampp\htdocs\projects\codeigniter\fastpay-payment-gateway\fastpay\vendor\symfony\http-foundation\Request.php
    Line: 314
    Function: createRequestFromFactory
    
    File: C:\xampp\htdocs\projects\codeigniter\fastpay-payment-gateway\fastpay\vendor\ngekoding\codeigniter-datatables\src\DataTables.php
    Line: 41
    Function: createFromGlobals
    
    File: C:\xampp\htdocs\projects\codeigniter\fastpay-payment-gateway\fastpay\application\controllers\user\Devices.php
    Line: 41
    Function: __construct
    
    File: C:\xampp\htdocs\projects\codeigniter\fastpay-payment-gateway\fastpay\index.php
    Line: 315
    Function: require_once
    
    bug 
    opened by pranaycb 4
  • Ambiguous column problem when searching with joined table

    Ambiguous column problem when searching with joined table

    The problem appear when we have the same column name with join. So, when the searching process, it try to search by that same column name, so it name getting ambiguous.

    For example:

    $queryBuilder = $this->db->select('p.*, c.name category')
      ->from('posts p')
      ->join('categories c', 'c.id=p.category_id');
    

    Posts and Categories table have a column name ID, it make the searching process error when to try search for ID.

    bug 
    opened by ngekoding 1
Releases(v1.0.6)
Owner
Nur Muhammad
Design and code with love.
Nur Muhammad
Server-side handler of DataTables Jquery Plugin for Laravel 4

Project is not being maintained actively. You will most likely find a better more actively maintained fork here https://github.com/yajra/laravel-datat

Bilal Gultekin 264 Jul 2, 2022
Easy Laravel Server-Side implementation of PrimeVue Datatables

Laravel + PrimeVue Datatables This is a simple, clean and fluent serve-side implementation of PrimeVue Datatables in Laravel. Features Global Search i

Savannabits 11 Dec 29, 2022
Fully customizable and tests supported Laravel admin dashboard for developers.

Laravel Admin dashboard Like Laravel Jetstream but built with Hotwire Turbo + additional perks. Tools used: tailwindcomponents/dashboard Hotwire Turbo

null 12 Nov 1, 2022
Data Table package with server-side processing, unlimited exporting and VueJS components

Data Table package with server-side processing, unlimited exporting and VueJS components. Quickly build any complex table based on a JSON template.

Laravel Enso 618 Dec 28, 2022
This package was created to deal with laravel datatables and cruds using vuejs.

datatable-cruds Installation This package was created to deal with laravel datatables and cruds using vuejs. Install the package through Composer. Run

Osama Saad 9 Dec 19, 2022
jQuery DataTables API for Laravel 4|5|6|7|8

jQuery DataTables API for Laravel 4|5|6|7|8 This package is created to handle server-side works of DataTables jQuery Plugin via AJAX option by using E

Arjay Angeles 4.5k Jan 9, 2023
Laravel 8 + CoreUI + Livewire + Datatables (CRUD)

Laravel 8 + CoreUI + Livewire + Datatables About Laravel 8 + CoreUI + Livewire Datatables Whats Inside Laravel Core UI - (https://github.com/HZ-HBO-IC

Muhammad Rheza Alfin 38 Nov 3, 2022
Laravel Datatables Package Demo App

#Laravel Datatables Demo App Datatables Package for Laravel 4|5 This package is created to handle server-side works of DataTables jQuery Plugin via AJ

Arjay Angeles 139 Dec 23, 2022
Livewire DataTables components for back-end. Modular, easy to use, with tons of features.

Livewire DataTables Livewire DataTables components for back-end. Modular, easy to use, with tons of features. Inspired by Caleb's Livewire Screencasts

Amir Rami 8 Jul 27, 2022
Laravel 8 + CoreUI + Livewire + Datatables (CRUD)

Laravel 8 + CoreUI + Livewire + Datatables About Laravel 8 + CoreUI + Livewire Datatables Whats Inside Laravel Core UI - (https://github.com/HZ-HBO-IC

Muhammad Rheza Alfin 38 Nov 3, 2022