How to access values from fnServerParams
How to access values from fnServerParams
systematical
Posts: 23Questions: 0Answers: 0
Hello I am using DataTables 1.9.4 and I would would like to access the values that have been passed in fnServerParams. The code is quite simple:
[code]
var oTable = $('#report-table').dataTable({
"iDisplayLength": 300,
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "/casings/index.json",
"sDom": 'Rfrtip',
"fnServerParams": function ( aoData ) {
aoData.push({ "name": "customer_id", "value": $('#customer-id').val() });
aoData.push({ "name": "shipped", "value": $('#shipped-status').val() });
}
});
[/code]
Unfortunately I don't know how to access the values passed into aoData in fnServerParams. I've tried the following to no avail as I don't see customer_id or shipped anywhere.
[code]
var settings = oTable.fnSettings();
console.log(settings);
console.log(oTable.oApi._fnAjaxParameters(oTable.dataTable().fnSettings()));
[/code]
Does anyone know how to do this?
[code]
var oTable = $('#report-table').dataTable({
"iDisplayLength": 300,
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "/casings/index.json",
"sDom": 'Rfrtip',
"fnServerParams": function ( aoData ) {
aoData.push({ "name": "customer_id", "value": $('#customer-id').val() });
aoData.push({ "name": "shipped", "value": $('#shipped-status').val() });
}
});
[/code]
Unfortunately I don't know how to access the values passed into aoData in fnServerParams. I've tried the following to no avail as I don't see customer_id or shipped anywhere.
[code]
var settings = oTable.fnSettings();
console.log(settings);
console.log(oTable.oApi._fnAjaxParameters(oTable.dataTable().fnSettings()));
[/code]
Does anyone know how to do this?
This discussion has been closed.
Replies
Allan
I alsio don't understand what you are asking me to do. Is it possible to provide example code?
Not really, because I don't understand the problem! Why do you want to access a variable that you are adding to the array? Why wouldn't you just use it directly in your Javascript?
Allan
And here is an example of how I use this plugin:
[code]
var oTable = $('#report-table').dataTable({
"iDisplayLength": 300,
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "/casings/index.json",
"sDom": 'frtipX',
"fnServerParams": function ( aoData ) {
aoData.push({ "name": "customer_id", "value": $('#customer-id').val() });
aoData.push({ "name": "shipped", "value": $('#shipped-status').val() });
}
});
[/code]
Now this is working fine, it adds the DIVs exactly where I want them and my click events are working superbly. The finally piece is getting everything I am sending /casings/index.json and sending it to another URL to generate the XLS and PDF sheets.
I'm still not exactly clear on what you are wanting to do I'm afraid. You want your feature plug-in `X` to be able to access the contents of fnServerParams? Do you want that to happen before the Ajax request? Or do you want it to happen after?
If after, DataTables 1.10 has a new `ajax.params()` method. For before - you would almost certainly need to insert some code into DataTables since, although there is a callback that plug-ins can use to add parameters, there isn't one after that initial callback once the parameters have been setup.
Allan