Migrating to 2.0.0

Migrating to 2.0.0

mdellanave83mdellanave83 Posts: 33Questions: 3Answers: 0

Hi,
I read about the fact that the legacy function fnServerData it's no longer available in the last 2.0.0 version.

The question is, is there a way to use something similar?

In my use case, in the previous versions, I was able to use that function to call a rest api service and fill the table using the fnCallback({iTotalRecords, iTotalDisplayRecords, aaData})

Now I've tried to use the option ajax, as a function that do the same stuff, but I don't know exactly how to give back the data to the dataTables (fnCallback is undefined)

Some idea?

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin

    Yes, use ajax as a function. It is more or less the same thing (ajax as a function has been in since 1.10 in 2014!).

    Allan

  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin
    Answer ✓

    Now I've tried to use the option ajax, as a function that do the same stuff, but I don't know exactly how to give back the data to the dataTables

    Sorry - I missed this bit. The callback function is passed into your own function. I've called in callback in the documentation, but you could name it anything you want:

    new DataTable('#myTable', {
      "ajax": function (data, callback, settings) {
        var data = ...;
        callback( data );
      }
    } );
    

    Note that the names of the parameters for the returned data have also been changed, see the docs here.

    There is some more discussion about this in the 1.10 upgrade notes - note that the legacy.ajax option isn't available in 2 any more (although it would be fairly easy to map parameters across if you needed to).

    Allan

  • mdellanave83mdellanave83 Posts: 33Questions: 3Answers: 0

    Thank you @allan!
    I noticed the params changes after I wrote this post, so now I'm using the ajax option as function and it seems to works.

    have a nice day

  • mdellanave83mdellanave83 Posts: 33Questions: 3Answers: 0

    Hi @allan
    I have one doubt, I'm still using
    {iTotalRecords, iTotalDisplayRecords, aaData}
    as the param object of the callback (I'm using pagination)

    Do you think it's right?
    Or maybe there's a newer object shape to pass?

  • kthorngrenkthorngren Posts: 21,322Questions: 26Answers: 4,948
    Answer ✓

    You will probably want to use the current parameter names as described in the Server Side Processing protocol docs.

    Kevin

  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin
    Answer ✓

    Yup, the old parameter names from before 1.10 have now been removed in 2. Time to update them :)

    Allan

Sign In or Register to comment.