(Legacy 1.9) Get data for current rows (from AJAX source)

(Legacy 1.9) Get data for current rows (from AJAX source)

errorerror Posts: 2Questions: 2Answers: 0

I am trying to build a custom renderer for a datatable in the legacy version. Rather than display the data as a table I want to display them as divs in a different container. To achieve this, I have hidden the table node and added a draw event that should get the currently displayed rows and then create corresponding divs instead.

In principle this seems to work, but I can't figure out the correct way to get the data corresponding to the currently displayed rows.

Initially I tried to use something like this:

for(var i = oSettings._iDisplayStart; i < oSettings._iDisplayStart + oSettings._iDisplayLength && i < oSettings.aiDisplay.length; i++) {
var row = oSettings.aoData[oSettings.aiDisplay[i]];
if(!row) return;
var data = cardRow._aData;
...
}

This seemed to work fine when I set aoData manually on initialization. However, when using an AJAX source with fnServerData this doesn't seem to find the data anymore after I click the next page button. I suspect this has something to do with _iDisplayStart being larger than the length of aiDisplay in this case, since old AJAX data is maybe not kept around?

I also found another solution which I thought should work, getting the data through oSettings.oInstance._('tbody tr', {'filter': 'applied', 'page': 'current'})

Unfortunately this again fails when using fnServerData. It works fine for the first draw, but as soon as I click the next page button I get this error:

Uncaught TypeError: Cannot read property 'nTr' of undefined
    at n.fn.init.$ (xxx)
    at n.fn.init._ (xxx)

If anyone could tell me what the correct way to do this is I would be immensely grateful!

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    This does sound fiddly, and the best way would be to use the newer releases as there's more functionality there (and better supported). Would it be possible for you to update to the 1.10.x releases?

    Colin

This discussion has been closed.