Best way to render boolean data columns in jquery datatables.net

I am using datatables.net data grid with jquery and bootstrap . I have a big chunk of JSON data with some boolean columns in it and would like to display the datatables column as a checked or unchecked checkbox (all this, of course, with self-tuning). What is the easiest / fastest to do?

+6
source share
2 answers

I answered my question :-) actually very simple:

var simple_checkbox = function ( data, type, full, meta ) { var is_checked = data == true ? "checked" : ""; return '<input type="checkbox" class="checkbox" ' + is_checked + ' />'; } var setup_datatable = function () { $('#data-table').DataTable({ "columns": [ { "data": "id", "className": "text-center"}, { "data": "keywords"}, { "data": "platform"}, { "data": "is_active", "render": simple_checkbox}, { "data": "is_terminated", "render": simple_checkbox} ], "ajax": "/data" }); // DataTable } 
+20
source

Adding a disabled class will remove the function on the page, but retain the look.

 var simple_checkbox = function (data, type, full, meta) { var is_checked = data == true ? "checked" : ""; return '<input type="checkbox" **class="checkbox disabled"** ' + is_checked + ' />'; } 
+2
source

Source: https://habr.com/ru/post/979059/


All Articles