Skip to content

Instantly share code, notes, and snippets.

@gustinmi
Last active December 13, 2015 17:59
Show Gist options
  • Save gustinmi/4952465 to your computer and use it in GitHub Desktop.
Save gustinmi/4952465 to your computer and use it in GitHub Desktop.
jQuery Tables plugin. Below is the code that triggers the update ajax source via your own custom event handler, possibly passing http paramaters.
//This is the extension function for table plugin (My params are array of key value pairs). Make this script available to your //web page which is utilizing the table plugin
$.fn.dataTableExt.oApi.fnReloadAjax = function (oSettings, sNewSource, myParams ) {
if ( oSettings.oFeatures.bServerSide ) {
oSettings.aoServerParams = [];
oSettings.aoServerParams.push({"sName": "user",
"fn": function (aoData) {
for (var i=0;i<myParams.length;i++){
aoData.push( {"name" : myParams[i][0], "value" : myParams[i][1]});
}
}});
this.fnClearTable(oSettings);
this.fnDraw();
return;
}
};
//Example usage to put in you refresh event listener
var oTable;
if (oTable == null) {
oTable = $(".items").dataTable(); //code for your data table
}else{
oTable.fnReloadAjax(oTable.oSettings, supplier, val);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment