Syn Syn - 4 months ago 34
jQuery Question

How does DataTables output a table with server side processing?

I am using DataTables server side ( to create a paginated table from a MySQL table.

I have created a simple table using DataTables:

I would like to work out how DataTables generates the table, as I cannot seem to find any occurrence of

in the script.

DataTables currently outputs something similar to this:

<tr class="odd" role="row">
<td class="sorting_1">[mysql result]</td>

I want to be able to add extra code alongside the MySQL output. For example, to turn the output into a hyperlink:

<tr class="odd" role="row">
<td class="sorting_1"><a href="[mysql result]">[mysql result]</a></td>

But I cannot do this as I cannot work out where DataTables is outputting the HTML code.

Any suggestions?


You need to use render for this:

$(document).ready(function() {
    $('#example').DataTable( {
        "processing": true,
        "serverSide": true,
        "ajax": "pull_2.php",
        "columns": [
               "render": function (data, type, full, meta) {
                    return "<a href=" + full[0] + ">" + full[0] +"</a>"

In this example let's say you are returning a dataset with 1 column of data. Within render, you build the hyperlink with html and an indexed reference to the row of data. full represents the entire row.

If you were returning multiple columns, you could build the hyperlink with different fields, e.g. an Id for the hyperlink, and a string for the link text.