Skip to content

Instantly share code, notes, and snippets.

@orangexception
Created February 17, 2012 16:53
Show Gist options
  • Save orangexception/1854342 to your computer and use it in GitHub Desktop.
Save orangexception/1854342 to your computer and use it in GitHub Desktop.
Populating Export Fields when DataTable changes
// Add to callback chain from DataTable.fnDrawCallback, assumes target DataTable is global variable called oTable.
function onDataTableSearchSortAndFilterChangeHandler () {
$( "#sSearch" ).val(
$( ".dataTables_filter label input" ).val() );
if( typeof( oTable ) === "undefined" )
return;
var aaSorting= oTable.fnSettings().aaSorting;
$( "#iSortingCols" ).val( aaSorting.length );
for( var iOuterRow= 0;
iOuterRow < aaSorting.length;
iOuterRow++ ) {
$( "#exportForm" ).append( '<input type= "hidden" name= "iSortCol_' + iOuterRow + '" id= "iSortCol_' + iOuterRow + '" />' )
$( "#exportForm" ).append( '<input type= "hidden" name= "sSortDir_' + iOuterRow + '" id= "sSortDir_' + iOuterRow + '" />' )
$( "#iSortCol_" + iOuterRow ).val( aaSorting[ iOuterRow ][ 0 ] );
$( "#sSortDir_" + iOuterRow ).val( aaSorting[ iOuterRow ][ 1 ] );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment