Datatables Add, Read, Edit, Delete, Export and Custom Filter Using Codeigniter with Ajax

A Table is an arrangement of columns and rows that organizes and positions data. DataTables is a table enhancing plug-in for the jQuery Javascript library, adding sorting, paging, and filtering abilities to plain HTML tables with minimal effort.
In this tutorial you will learn about jQuery Datatables Add, Read, Edit, Delete, Export, and Custom Filter Using Codeigniter with Ajax. We will handle to refresh Datatables when any record updated or delete from the table. This is a very simple example, you can just copy-paste, and change according to your requirement.
Before started to implement the jQuery Datatables plugin, look files structure:
  • server-side-datatables-custom-filter-using-codeigniter
    • application
      • config
        • constants.php
        • database.php
        • routes.php
      • controllers
        • Curd.php
      • models
        • Curd_model.php
      • views
        • employees
          • index.php
            • popup
              • add.php
              • display.php
              • edit.php
              • delete.php
              • renderEdit.php
              • renderDisplay.php
        • templates
          • header.php
          • footer.php
    • system
    • index.php
    • assets
      • css
        • style.css
      • js
        • custom.js
Step 1: Create MySQL Database and Table
Step 2: Create a model file
Create a model file named “Curd_model.php” inside “application/models” folder.
Step 3: Create a controller file
Next create a controller file named “Curd.php” inside “application/controllers” folder.
Step 4: Change Route file
So open “application/config/routes.php” file and add code like as bellow:
Step 5: We will include these necessary Datatable plugin files to load Datatable and export data.
We have define HTML table for initialization jQuery Datatable plugin on this page based on id selector: #render-datatable.
Step 6: Create a view
Create a view file named “index.php” inside “application/views/employees” folder.
Step 6: Create a view
Create a view file named “add.php” inside “application/views/employees/popup” folder.
Step 7: Create a view
Create a view file named “display.php” inside “application/views/emp/popup” folder.
Step 8: Create a view
Create a view file named “renderDisplay.php” inside “application/views/emp/popup” folder.
Step 9: Create a view
Create a view file named “edit.php” inside “application/views/emp/popup” folder.
Step 10: Create a view
Create a view file named “renderEdit.php” inside “application/views/emp/popup” folder.
Step 11: Create a view
Create a view file named “delete.php” inside “application/views/emp/popup” folder.
Step 12: Create a js file
Create a view file named “custom.js” inside “assets/js” folder.