Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DataTables, Ajax Pipelining

I'm using DataTables with pipelining. I works great except when I tried to enter an extra column to hold "edit" links. See this table.

Here is a snippet of server_processing.php showing the columns:

   /* Array of database columns which should be read and sent back to DataTables.
    * Use a space where you want to insert a 
    * non-database field (for example a counter or static image)
    */
    $aColumns = array( 'user','email', ); 

And here is the clientside:

    $(document).ready( function (){
       $('#example').dataTable({
          "bProcessing": true,
          "bServerSide": true,
          "sAjaxSource": "scripts/server_processing.php",
          "fnServerData": fnDataTablesPipeline,
          aoColumns: [null, null, {"bSortable": false}]
    }).makeEditable({
       sUpdateURL: "UpdateData.php",
       sAddURL: "AddData.php",
       sAddHttpMethod: "POST",
       sDeleteURL: "DeleteData.php",
       sDeleteHttpMethod: "POST",
       aoColumns: [ { } , { } , null ]
    });
  });

So, why isn't this working?

like image 901
Chad Avatar asked Jul 12 '11 20:07

Chad


1 Answers

Just done this exact same thing myself. I like to configure all my columns using aoColumnDefs, as you can add multiple configuration options for columns in one go.

// Disable sorting on the 3rd column
'aoColumnDefs': [{'aTargets': [2], 'bSortable': false}]

Note that aTargets is an array of column indexes you want to apply those settings to. So if you were to add more link columns (e.g. a Delete link), you can turn off sorting on those without rewriting the column definition every time.

// Disable sorting on the 3rd and 4th column
'aoColumnDefs': [{'aTargets': [2,3], 'bSortable': false}]

And, as I was saying, you can add further configuration options for columns in this same array:

// Disable sorting on the 3rd and 4th column and sort 1st column by string
'aoColumnDefs': [
    {'aTargets': [2,3], 'bSortable': false}
    {'aTargets': [0], 'sType': 'string'}
]
like image 88
BadHorsie Avatar answered Sep 23 '22 08:09

BadHorsie