Migrate to DataTables 1.10 - fnServerData

Migrate to DataTables 1.10 - fnServerData

soltestsoltest Posts: 3Questions: 1Answers: 0

The (old to new) mapping for both sAjaxSource and fnServerData is ajax: 1.9 to 1.10 Mapping

How can I convert the following DataTables initialization from 1.9 to 1.10?
(Just for these 2 options: sAjaxSource and fnServerData)

customersTable = $('#CustomersGrid').DataTable({
        "jQueryUI": true,
        "serverSide": true, 
        "sAjaxSource": "/Division/TX/GetAllCustomers",
        "fnServerData": function (sSource, aoData, fnCallback) {
            $.getJSON(sSource, aoData, function (json) {
                fnCallback(json);
            });
        }, ...

Answers

  • RpiechuraRpiechura Posts: 98Questions: 3Answers: 14
    edited June 2014

    sAjaxSource maps to ajax.dataSrc (http://datatables.net/reference/option/ajax.dataSrc ) and I'm fairly certain that the fnServerData maps to the callback feature inside the ajax method (half way down the page at http://datatables.net/reference/option/ajax ). So my understanding of how this would look after the translation is

    customersTable = $('#CustomersGrid').DataTable({
            ...,
            "ajax" : {
                "dataSrc":"/Division/TX/GetAllCustomers",
               function (data, callback, settings) {
                callback(
                    //Whatever logic you need to do to parse the Json
                )};
            }, 
            ...
        });
    

    If it works let me know. I've been putting off transitioning my syntax from old to new because I wasn't sure about some of the same stuff.

  • soltestsoltest Posts: 3Questions: 1Answers: 0

    How do you define the callback function INSIDE the ajax object?
    It doesn't work the way it is specified above.

  • RpiechuraRpiechura Posts: 98Questions: 3Answers: 14

    The link I gave shows some examples of how to define the callback. I did forget the function declaration on it though. I will say that the link doesn't show how to use the two together, so I can't give a better example, you'll just have to look at the link and piece it together.

  • northamericannorthamerican Posts: 5Questions: 2Answers: 0

    Any solutions to this? The conversion table to 1.10 does not explain how OP's table would be converted to 1.10.

  • northamericannorthamerican Posts: 5Questions: 2Answers: 0
    edited October 2014

    apparently, OP's "fnServerData" function does nothing necessary. fnServerData is a pre-defined function and OP's doesn't override any default behaviour...

    so as far as i can see:

    ajax: {
        src: "/Division/TX/GetAllCustomers"
    }
    

    would probably work the same in OP's case.

    my 1.9 method:

    "sAjaxSource": "/my/path",
    "fnServerData" : function ( sSource, aoData, fnCallback ) {
    
        aoData.push({ "name":"someKey", "value": "someValue" });
    
        $.getJSON( sSource, aoData, function (json) {
            fnCallback(json);
        });
    },
    

    became:

    ajax: {
        url: '/my/path',
        data: function ( data ) {
            data.someKey =  someValue;
        },
    },
    
This discussion has been closed.