Why does server-side callback param need old format?

Why does server-side callback param need old format?

ross_cohenross_cohen Posts: 3Questions: 1Answers: 0
edited June 26 in Free community support

New to DataTables, and I've been experimenting with version 2.3.2. I have server-side data-handling working, having one test page that uses an MVC controller, while a separate page (Blazor) uses a jsInterop circuit. With the MVC controller everything works as expected. However, with the jsInterop circuit I had to do some slight (but unexpected) fiddling to get it to work as expected (see the red square below):

As one can see, the json fetched from the server has "data", "draw", "recordsTotal", and "recordsFiltered" (exactly the same as what works in the case of the MVC controller) , but here the callback function insists on the old format, and when I give it the old format, it's happy and everything works as expected. Is this a bug, or is there something about my code that is (in effect) telling DT to insist on the old data format? It's a slightly niggly thing, but I'd like to sort this out.

Thanks,
Ross

Answers

  • allanallan Posts: 64,643Questions: 1Answers: 10,687 Site admin

    Hi Ross,

    The way the code works is that it will check to see if the old parameter is present (source code), and if so, then use it. If not, it uses the the "modern" one.

    It looks to me that you should simply be able to do: dtCallback(response); in the above. I'd need a link to a test case showing the issue to be able to understand why it isn't working if that doesn't work.

    Allan

  • charlesrhowardcharlesrhoward Posts: 3Questions: 0Answers: 0

    I’ve seen something like this before when using jsInterop. Even if the JSON format looks correct, sometimes DataTables expects things slightly differently depending on how it's initialized.

    Maybe try setting dataSrc: 'data' explicitly in your config. That helped me once in a similar situation.

  • allanallan Posts: 64,643Questions: 1Answers: 10,687 Site admin

    If you are using server-side processing, you need to use ajax.dataSrc as an object to tell it where to find the various parts of the sever-side data feed.

    Is the jsInterop you are referring to the one in ASP.NET Core Blazor? @ross_cohen - what platform are you using?

    Allan

  • ross_cohenross_cohen Posts: 3Questions: 1Answers: 0

    Thanks for your help, all. The new params now work as expected -- though for the life of me I can't see what I changed. I originally had the new params (at least I thought I did), then tried the old ones, and then changed back to the new ones -- and it now works with the new ones. Obviously, something must have changed (maybe I had originally mis-pelled a param)? Again, thanks for your time...

    Ross

  • ross_cohenross_cohen Posts: 3Questions: 1Answers: 0
    edited June 30

    In the hope that others might find it useful, here is my finished/fixed Blazor/JSInterop -- boiled down and clarified:

  • allanallan Posts: 64,643Questions: 1Answers: 10,687 Site admin

    Nice one - many thanks! Good to hear you got it working.

    Allan

Sign In or Register to comment.