Sorting: change iSortCol_0=2 to iSortCol_0=id
Sorting: change iSortCol_0=2 to iSortCol_0=id
Hello
When I press on table header cell it makes sorting by this cell and ajax request pass variable like iSortCol_0=2, where 2 - is cell number in the . So, how make dataTable to send something other, say 'id' instead of 2, is that possible?
Thanks
When I press on table header cell it makes sorting by this cell and ajax request pass variable like iSortCol_0=2, where 2 - is cell number in the . So, how make dataTable to send something other, say 'id' instead of 2, is that possible?
Thanks
This discussion has been closed.
Replies
because both the fnServerData and fnServerParams functions pass in the aoData (each aoData array element is an object with values .name and .value like aoData[0].name / aoData[0].value) you can run through the aoData array for the iSortCol_ variables and create a list of column title based entries, then just append these objects to the aoData.
something like this:
[code]
"fnServerParams": function ( aoData ) {
aoTitles = []; // this array will hold title-based sort info
oSettings = this.fnSettings(); // the oSettings will give us access to the aoColumns info
i = 0;
for (ao in aoData) {
name = aoData[ao].name;
value = aoData[ao].value;
if (name.substr(0,"iSortCol_".length) == "iSortCol_") {
// get the column number from "ao"
iCol = parseInt(name.replace("iSortCol_", ""));
// get the sTitle for this iCol column (accessed by column in value, which is aoData[ao]
sTitle = "";
if (oSettings.aoColumns[value]) sTitle = oSettings.aoColumns[value].sTitle;
// you should add some error checking here to handle if sTitle is not found
// not sure what you want to do in that case so I'll just ignore it
// create an entry in aoTitles (which will later be appended to aoData) for this column
aoTitles.push( { name: "iSortTitle_"+iCol, value: sTitle});
i++;
}
}
// for each entry in aoTitles, push it onto aoData
for (ao in aoTitles) aoData.push( aoTitles[ao] );
}
[/code]
this should add to the query string values like:
iSortTitle_0=id&iSortTitle_1=firstname&iSortTitle_2=qualification