I have a datatable from ajax source. I want to display a checkbox in one column based on its value.
If the value is active
, checkbox should be checked
, otherwise it remains unchecked
.
I am using Switchery JS
to stylize the checkbox. It works fine in normal HTML body
, but not inside a datatable column.
Here is the fiddle:
The problem is that you are doing the Switchery' before the dataTable is populated with data. And even if you did it after, you would still end up not having Switcherys on hidden rows, i.e on page
#2
,#3
and so on.So you must initialise Switchery after the dataTable is initialised and do the Switchery on all rows. You can do this in the
initComplete()
callback, and iterate over all rows by using the APIevery()
method :forked fiddle -> https://jsfiddle.net/jpkysyp1/