Data sent to server being corrupted when using columnFilter
Data sent to server being corrupted when using columnFilter
I am using Datatables version 1.10.1-dev (build dev-master#786d79d1a924df819a986efede259f92e1bab62f) with columnFilter (version 1.5.6). I initialize the datatable to do all updates serverside with code like:
var datatable_options = {
serverSide: true,
processing: true,
aLengthMenu: [
[10, 25, 50, 100, -1],
[10, 25, 50, 100, "All"]
],
iDisplayLength: 25,
ajax: {
url: <specified url>,
type: 'POST',
data: function ( d ) {
d.param1 = "value1";
d.param2 = "value2";
...
},
dataSrc: function(response) {
return response.data;
}
},
scrollX: true,
columns: [{"data":"fixed_lot_multiplier","orderable":false},{"data":"id","title":"Price","orderable":false},{"title":"FamilyName","data":"FamilyName","orderable":true,"searchable":true,"defaultContent":""},{"title":"Product Code","data":"product_code","orderable":true,"searchable":true,"defaultContent":""}],
order: [[first_orderable, 'asc']],
search: {search: s}
};
var dataTable = jQuery('#my_table').datatable(datatable_options);
All requests and are Ok, until I add code for the datatable to work with columnFilter
columnFilter({
sPlaceHolder: 'head:after',
aoColumns: [null, null, {}, {}]
});
At this point, data sent to the server which is an object or array of objects is sent as the string "object" instead of its JSON string value. Additionally, the second time a data request is sent, the additional data I add in the data
function is not added.
Why does this happen? Because columnsFilter uses the parameter fnServerData
parameter. When using this parameter, the data sent is converted from an object to an array of objects [{name: 'param1', value: object}, {name: 'param2', value: object}]
. (jquery.dataTables.js line 2367).
delete ajax.data;
Also, the data
function is overwritten (jquery.dataTables.js lines 2410-2412) and not returned to its original state after the request.
oSettings.fnServerData.call( instance,
oSettings.sAjaxSource,
$.map( data, function (val, key) { // Need to convert back to 1.9 trad format
return { name: key, value: val };
} ),
fn,
oSettings
);
Is there a different version I should use or parameters that I could send to either datatables or columnFilter that would make this work correcly?
Answers
do you have a test case to look at ?? How to submit a test case: https://www.datatables.net/manual/tech-notes/10