datatables boolean column checkbox

Solutions on MaxInterview for datatables boolean column checkbox by the best coders in the world

showing results for - "datatables boolean column checkbox"
Emil
23 Nov 2019
1var simple_checkbox = function ( data, type, full, meta ) {
2    var is_checked = data == true ? "checked" : "";
3    return '<input type="checkbox" class="checkbox" ' +
4        is_checked + ' />';
5}
6
7var setup_datatable = function () {
8    $('#data-table').DataTable({
9        "columns": [
10            { "data": "id", "className": "text-center"},
11            { "data": "keywords"},
12            { "data": "platform"},
13            { "data": "is_active", "render": simple_checkbox},
14            { "data": "is_terminated", "render": simple_checkbox}
15        ],
16        "ajax": "/data"
17    }); // DataTable
18
19}
20
Laura
24 Mar 2020
1// Handle form submission event
2$('#frm-example').on('submit', function(e){
3   var form = this;
4
5   // Iterate over all checkboxes in the table
6   table.$('input[type="checkbox"]').each(function(){
7      // If checkbox doesn't exist in DOM
8      if(!$.contains(document, this)){
9         // If checkbox is checked
10         if(this.checked){
11            // Create a hidden element
12            $(form).append(
13               $('<input>')
14                  .attr('type', 'hidden')
15                  .attr('name', this.name)
16                  .val(this.value)
17            );
18         }
19      }
20   });
21});