How to access values from fnServerParams

How to access values from fnServerParams

systematicalsystematical Posts: 23Questions: 0Answers: 0
edited March 2014 in DataTables 1.9
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?

Replies

  • allanallan Posts: 61,722Questions: 1Answers: 10,108 Site admin
    I don't quite understand why you would need to access the values that you are adding, but `aoData` is an array, so you would need to loop over it can find the `name` parameter for the parameter you want.

    Allan
  • systematicalsystematical Posts: 23Questions: 0Answers: 0
    edited March 2014
    Yes that does sound a bit strange doesn't it. I am working on replacing Table Tools with my own server-side XLS / PDF solution.

    I alsio don't understand what you are asking me to do. Is it possible to provide example code?
  • allanallan Posts: 61,722Questions: 1Answers: 10,108 Site admin
    > 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
  • systematicalsystematical Posts: 23Questions: 0Answers: 0
    Allan, this is because I am writing a plugin. We are heavily using datatables in one of our products. I am not going to go into each instance of where we are using datatables (probably over 30) and "access" the variables being added. I rather just create a plugin, give it an sDom name and type "X" wherever I want this functionality. Perhaps I should have been more thorough in my description of what I was doing, I figured this would be easy to do and someone would just respond with "call this function" or "just access this variable". Here is an example of the plugin I am creating (very new to this): http://pastebin.com/XGPqXNK8

    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.
  • systematicalsystematical Posts: 23Questions: 0Answers: 0
    Given what I've deduced by combing/hacking through all the datatables code and the lack of response to this thread I'm thinking that this is not possible...
  • allanallan Posts: 61,722Questions: 1Answers: 10,108 Site admin
    Sorry for the lack of reply. I'm struggling to keep up with the 40+ posts per day in the forum and some slip through the net despite my efforts.

    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
  • systematicalsystematical Posts: 23Questions: 0Answers: 0
    edited March 2014
    Thanks. This works and I am okay with using a beta version to get the functionality. When I'm done with the plugin I'll let you know.
This discussion has been closed.