Ignore Missing Columns In Ajax Data (Dynamic Columns)

Ignore Missing Columns In Ajax Data (Dynamic Columns)

theAnimalixtheAnimalix Posts: 35Questions: 12Answers: 2
edited October 2016 in Free community support

Hey,

I'm currently hiding columns by sending some additional data attached to DataTables payload (ajax). I'm using ajax.complete callback to get that additional data and and show columns (which should be initially hidden via "never" class):

$(table.column(index + ':name').header()).removeClass('never').addClass(value);

I like this approach since some basic columns visible to all are are rendered right after DataTables init, only the more sensitive columns are displayed after the ajax complete.

This works great, but I still have to provide empty column values in servers JSON response, since if I remove specific columns from that JSON, DataTables will show an warning alert.

DataTables warning: table id=table - Requested unknown parameter 'name' for row 0, column 1.

Today I wanted to improve that since I don't like the idea about sending those empty values just to avoid the problem mentioned above.
Is there maybe an event/callback I could use to add that missing combination of column name and empty value to row (if they are missing), just before the row is processed (before that warning popup)?

Is there any way for DataTables to ignore missing columns?

Another way I thought about id to use ajax.dataFilter callback, but don't like the idea of looping through all rows just for that (or even doing the same on server).

Would appreciate any suggestions about improving this.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,818Questions: 1Answers: 10,517 Site admin
    Answer ✓

    This works great, but I still have to provide empty column values in servers JSON response, since if I remove specific columns from that JSON, DataTables will show an warning alert.

    Use columns.defaultContent for those columns. That way, if the server doesn't supply the values for those columns, the defaultContent value will be used (usually just an empty string will do).

    Allan

  • theAnimalixtheAnimalix Posts: 35Questions: 12Answers: 2

    Thanks for that Allan, it works perfect!

This discussion has been closed.