how get current value of checkbox?

how get current value of checkbox?

KamoAKamoA Posts: 19Questions: 6Answers: 0
edited November 2019 in Free community support

I use this code to define check boxes in my table:

columnDefs: [{targets: [2,4], 
                render: function ( data, type, row ) {
                    if ( type === 'display' ) {             
                        return '<input type="checkbox" ' + ((data == 1) ? 'checked' : '') + ' id="input' + row.id + '" class="filter-ck" />';
                    }
                    return data;
                  },
                  className: "dt-body-center"
                 },
                 {targets: 0, className: "dt-body-center"},

              ],
            select: {
            style: 'os',
            selector: 'td:not(:nth-child(2))'
        },

and

then I do:

var table = $('#GRID_1').DataTable();
$('#GRID_1 tbody').on( 'click', 'tr', function () {
        if ( $(this).hasClass('selected') ) {
            $(this).removeClass('selected');
        }
        else {
            table.$('tr.selected').removeClass('selected');
            $(this).addClass('selected');

alert(table.cell('.selected',2).data());

        }
    } );

    } );

but
table.cell('.selected',2).data() gives me original data from cell.
How can I get current value of check box?

Thank you.
Kamo.

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598
    edited November 2019

    You can use cells().render() to get the display values - something like table.cells(null, 2).render('display').

    Colin

  • KamoAKamoA Posts: 19Questions: 6Answers: 0

    it gives me:
    <input type="checkbox" id="inputundefined" class="filter-ck">
    or
    <input type="checkbox" checked id="inputundefined" class="filter-ck">

    from original data.
    I cannot see 'checked' as current value.
    Any other way I can get this value?

  • kthorngrenkthorngren Posts: 21,166Questions: 26Answers: 4,921
    Answer ✓

    The easiest way to get the checkbox checked state is with jQuery. See this example:
    http://live.datatables.net/xetowopa/1/edit

    Kevin

  • KamoAKamoA Posts: 19Questions: 6Answers: 0

    Thank you! It work's!

  • KamoAKamoA Posts: 19Questions: 6Answers: 0

    How can I set this checkbox value in a specific cell (I have 2 columns with check boxes) data?
    I like to see this data later in
    table.cell('.selected',2).data().
    Is it possible?

This discussion has been closed.