Datatable column visible when value null

Datatable column visible when value null

OmerBenkyzzOmerBenkyzz Posts: 2Questions: 1Answers: 0

I have a 22 columns on my datatable and i am trying to check my 21 column when string value null unvisible with if,else
how can i do that can u help me
I am trying to check on if, else like that

var table = $('#utable').DataTable();


if (column[21] == empty) {   
    table.column().visible(true);  
    table.column().visible(true);  
}

else{
    table.column().visible(false);   
}

Answers

  • colincolin Posts: 12,481Questions: 0Answers: 2,117

    table.column().visible(true);

    would always set the visibility of column 0 to true - and you've duplicated that command on lines 5 and 6.

    I'm not too clear on what you're trying to do. Can you add some explanation , please.

    Colin

  • OmerBenkyzzOmerBenkyzz Posts: 2Questions: 1Answers: 0

    Hey Colin,

    hiding will be done according to the state of the row. If the 21st column of a row is empty, that column will be hidden for that row only.

  • kthorngrenkthorngren Posts: 13,606Questions: 25Answers: 3,204

    There is nothing built into Datatables to hide a column on a row by row basis. You can hide the whole column.

    If you hide the 21st column of only one row whet would happen with the rest of the columns to the right?

    Please describe the goal of doing this. Maybe we can offer suggestions.

    Kevin

  • tbonetbone Posts: 4Questions: 1Answers: 0

    How can you check if a column is empty and hide the column? Actually I know how to hide the column, just having a problem checking if the column is empty.

  • kthorngrenkthorngren Posts: 13,606Questions: 25Answers: 3,204

    @tbone Good question. I would use the filter() API to get all the column data that is not empty. Then use count() to see if there are any non-empty rows. Like this:
    http://live.datatables.net/rilumati/1/edit

    Kevin

Sign In or Register to comment.