hiding columns with no data

hiding columns with no data

0lo0lo Posts: 1Questions: 1Answers: 0

Ref the solution below.
https://www.datatables.net/forums/discussion/24638/hide-empty-columns-ajax-data#Comment_68327

I am also trying to hide columns based on my ajax dataset. But im very new to jquery and datatables both so need some more clarity on what to do.
I have created the table by specifying the columns in the aoColumns array.
We have a drop down on the page to select the desired backend server and based on that the ajax will return the dataset.
Now that i have specified the column name as below

"mDataProp": "column1", "sClass":"center col1",

when I load the page, it shows the values in column1 but when the ajax returns a dataset that does not have column1, it shows a popup saying something like "Requested Unknown parameter from datatsource for row0"

Where should I put the condition to ignore the column when the ajax does not return that column.

Answers

  • glendersonglenderson Posts: 231Questions: 11Answers: 29

    Based upon your error, it sounds like the number of expected columns are not matching the number of passed columns. If you define 5 columns, then your response data set must contain 5 columns worth of data. It sounds like you are dropping the column in your response because it empty. Inside, send / format / etc, the empty column as "". The example you referenced is hiding a column that has nothing (zero length) in all the rows of the column.

This discussion has been closed.