How to parse JSON data in jQuery Datatable

This Datatable jquery tutorial help to parse JSON data which was received from server side.I got huge response from reader on datatable tutorials,i am sharing next level datatable tutorial with php and mysql,I am extending Datatable Pagination, Sorting and Search – Server Side (PHP/MySQl) Using Ajax.

Sometimes we need to add some text,process json data or filter JSON object data before to send datatable jQuery table.I am using Datatable in-build call back dataSrc() function which will parse JSON data as your requirement and send to datatable.

This tutorial will help to achieve following milestone,

  • Added Hyperlink(Anchor HTML tag) on column in jquery datatable.
  • Added img HTML tag in table td column.
  • Added edit/delete and view action button.

Also Checkout other tutorial of jQuery Datatable,

I am are using below Files in this tutorial

Index.php - This file will responsible to create html and instance datatable using jquery code.
response.php - This file responsible to create database connection string and convert records into json string and returns data to Ajax method as response.
connection.php - This file responsible to create mysql database connection.

I already mentioned in this post i am extending Datatable Pagination, Sorting and Search – Server Side (PHP/MySQl) Using Ajax, so i assumed you have read and understand that tutorial.

How to parse JSON data in jQuery Datatable

Step 1: we will create new profile_image column in employee table. This column will store profile image path.

Step 2: Added profile_image column in $column array in response.php file.

Step 3: Added profile_image and Action column in HTML table header and footer heading in index.php file.

Step 4: We will user dataSrc callback jquery datatable function to parse JSON object.This function will take JSON data as a parameter which will returned from Ajax request.

as you can see above code, I am adding following functionality,

  1. Adding img html tag with profile_image column value
  2. Adding href attribute on each name column value
  3. Adding new column Action column which will take edit/delete and view anchor tag


We have learn how to parse received server JSON object in client side and send to jQuery datatable.This jQuery tutorial help to add or modified JSON object before render datatable in HTML table format.We have added Image and anchor HTML tag with column value in td.

You can download source code and Demo from below link.

6 thoughts on “How to parse JSON data in jQuery Datatable

  1. Thanks Parvez for share with img and action tag
    but i have some queries,

    I need to use if condition on data
    i have a filed that name gender and values are 0 and 1 (0=male,1=female)

    i want to display male for 0 and female for 1 rather then 0 and 1

    please help me to solve out this.

    Thank You.

  2. what if i have 20 fields and i just want to shown all records from 6 fields.. it will located at the first field, middle field and in the end field.. how do i do that.. please help.. thanks in advance.

  3. in js side,
    You need to unset those index fields in ajax
    “dataSrc”: function (jsonData) {
    for ( var i=0, ; i<len ; i++ ) {
    jsonData.splice( i, 1 );
    Server side:
    You can send response of those col values/index which u need to show in table

  4. Hello, first of all thanks a lot! this is awesome! I would like to know how to replace de # link in your example for an URL that is in a 5th hidden column. should I just do this?[i][1] = ‘<a href="[i][5]" target="_blank">’[i][1]+'</a>’;

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.