table.column("#").visible() no longer falsey
table.column("#").visible() no longer falsey
JammySlayer
Posts: 39Questions: 11Answers: 2
It used to be that
if (table.column("#ID").length > 0 && table.column("#ID").visible()))
Would go down the false when the column didn't exist (it's not added in the initial render depending on permissions) but now the table.column("#ID").visible() is returning the datatable object, which javascript interprets as "yes there is an object" and enters the condition.
This question has an accepted answers - jump to answer
Answers
I can't recall off the top of my head why that changed I'm afraid - however, change:
to be:
or
and that will correct the expression.
The issue is that
.length
is giving a length of 1 due to an empty array, which is what I would actually expect to happen - no items were selected, so it is an empty array of selected items. It sounds like there was a bug in the old versions!Allan
Ah I see... misinterpreted the issue, I'd say .length == 0 feels more correct if the selector returned no columns, pretty sure jquery works to length == 0 when nothing has been found too?
The issue is that DataTables' API is multi-table aware. So there is an array of elements, inside the main array, one for each table that the API is operating on. So it actually looks like
[ [ ] ]
- which is why.length
of the first layer gives 1, but really there are no matches. Hence the use ofany()
orcount()
which are aware of that structure and account for it.Allan