Using an [ajax] Custom Get Function? Don't forget to set sAjaxDataProp !!

Using an [ajax] Custom Get Function? Don't forget to set sAjaxDataProp !!

ajoslin103ajoslin103 Posts: 20Questions: 4Answers: 0
edited April 2015 in DataTables 1.10

Documentation for ajax.dt in the API really needs an addition noting sAjaxDataProp !!

If you are using the 'ajax' property as a function (so that you can control how the parameters get sent to the server and process what comes back before DT gets at it) then you MUST set sAjaxDataProp to the name of the data object array in the json structure that you pass to the callback !!!

If you do not do this then DT cannot find your data object array, (it will not matter that you have named it 'data' as you think you are supposed to, or even 'aaData' as indicated elsewhere)

Do yourself a favor and set sAjaxDataProp to the name of your data object array !!

I found this using the most excellent DT Debugger !!

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    The ajax.dataSrc option replaces sAjaxDataProp in 1.10 if you are using the ajax option. sAjaxDataProp should not be required.

    Allan

  • ajoslin103ajoslin103 Posts: 20Questions: 4Answers: 0
    edited April 2015

    I was setting ajax = function

    I tried adding ajax.dataSrc both before and after that setting and it didn't seem to matter

    I am trying again, since I was flailing about a bit and can't be sure I tried this properly

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Ah yes, if you use ajax as a function, then you are expected to return the data array to the callback function. Thanks for the clarification.

    Allan

  • ajoslin103ajoslin103 Posts: 20Questions: 4Answers: 0
    edited April 2015

    yes, but therin lies the rub (as my dear old dad used to say,) when I returned the data array then the table had data but the pagination numbers didn't work -- and when I returned the json structure then the pagination numbers worked but the data was missing from the table.

    the only option that worked was to set sAjaxDataProp and return the json structure

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    I returned the data array then the table had data but the pagination numbers didn't work

    Odd. Are you using server-side processing? That might explain it... There could be a bug there if so.

    Allan

  • ajoslin103ajoslin103 Posts: 20Questions: 4Answers: 0

    yes, server side processing

    cool, I might get a bug named after me !!

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    Yes, just confirmed - this is a bug. I'll look into it for the next release. Thanks for letting me know about this.

    Allan

  • ajoslin103ajoslin103 Posts: 20Questions: 4Answers: 0

    you are welcome - I'm alway happiest when I'm using DT because it's so capable and complete!!

This discussion has been closed.