Always shown checkbox dependant on another column
Always shown checkbox dependant on another column
I've had a great deal of success with Editor's "Always shown checkbox", by following an older blog, and the example here:
https://editor.datatables.net/examples/api/checkbox.html
Now I want to show/hide the checkbox, based on another field, and I'm trying to decide best how to approach that, and I don't necessarily have a full understanding of what's required for display on return
- what is the significance of the final
return
statement? Is the code below returning the HTML markup explicitly for display, and the raw data for other "types", like filtering and sorting? - is a final
return data;
statement always required? - I have a situation where I what to SHOW or HIDE a checkbox, based on an adjacent column, which I can access with
row.TheOtherField
- Basically, if
(row.TheOtherField == null) {return ''}
-- don't show a checkbox. I don't want to show the raw data either. - Is it better to HIDE the checkbox (Bootstrap's d-none):
return '<input type="checkbox" class="editor-active d-none">';
? - Personally, I would rather "display nothing"
How do I display nothing? is it as simple as return ''
? (I've had some weird results. Maybe I'm just tired.)
{
data: "active",
render: function ( data, type, row ) {
if ( type === 'display' ) {
return '<input type="checkbox" class="editor-active">';
}
return data;
},
className: "dt-body-center"
}
This question has an accepted answers - jump to answer
Answers
columns.render
is called for various renderings - such as sort, display, type, etc. In your code snippet, it's doing something specific for thedisplay
type, everything else falls through and thedata
as-is returned.row
, the third argument, contains data for the entire row.that should work if you return
''
- if it's weird, please post a test case or link to your page, and we can take a lookColin