Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

call a function in success of datatable ajax call

Is that possible to invoke a javascript function in success of datatable ajax call. Here is the code am trying to use,

var oTable = $('#app-config').dataTable(             {                 "bAutoWidth": false,                                                                 "bDestroy":true,                 "bProcessing" : true,                 "bServerSide" : true,                 "sPaginationType" : "full_numbers",                 "sAjaxSource" : url,                                     "fnServerData" : function(sSource, aoData, fnCallback) {                     alert("sSource"+ sSource);                     alert("aoData"+ aoData);                     $.ajax({                         "dataType" : 'json',                         "type" : "GET",                         "url" : sSource,                         "data" : aoData,                         "success" : fnCallback                     });                 } 

is it possible to have something like,

success : function(){     //.....code goes here } 

instead of "success" : fnCallback ------> which is last line of AJAX call. In this function I would like to check a value send from server side. Thanks in advance for any help....

like image 757
rajan.tsm Avatar asked Apr 03 '13 11:04

rajan.tsm


2 Answers

You can use dataSrc :

Here is a typical example of datatables.net

var table = $('#example').DataTable({     "ajax": {             "type" : "GET",             "url" : "ajax.php",             "dataSrc": function ( json ) {                 //Make your callback here.                 alert("Done!");                 return json.data;             }            },     "columns": [             { "data": "name" },             { "data": "position" },             { "data": "office" },             { "data": "extn" },             { "data": "start_date" },             { "data": "salary" }                  ]     } ); 
like image 156
Joseph Garrone Avatar answered Sep 23 '22 15:09

Joseph Garrone


You can use this:

"drawCallback": function(settings) {    console.log(settings.json);    //do whatever   }, 
like image 40
AnasSafi Avatar answered Sep 21 '22 15:09

AnasSafi