CheckBox in searchpane instead of Select

CheckBox in searchpane instead of Select

valredrvalredr Posts: 21Questions: 7Answers: 0

Hi I have checked the below case from the forum and found that check boxes can be used in search pane
http://live.datatables.net/jayilaqa/1/edit

but what I want is the search filter need to be activated only on the chnage of the checkbox and not the select of the record in the search pane .
The current behavior is instead of the check box if clicked on the value in the search pane the filter gets set on the table and the check box remains unchecked

Is there someway fo getting both these thing in sync i.e select of record and set of checkbox or filter table just on set of check box

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,112Questions: 1Answers: 2,583
    Answer ✓

    That took some serious thought, but here it is :)

    The magic is in using Select extension events:

        $('.dtsp-searchPane table').DataTable().on('user-select', function(e, dt, type, cell, originalEvent) {
            console.log(originalEvent.target.nodeName);
            if (originalEvent.target.nodeName.toLowerCase === 'input') {
                e.preventDefault();
                dt.row(cell.index().row).select();
            }
        });
    
        $('.dtsp-searchPane table').DataTable().on('select deselect', function(e, dt, type, idx) {
            dt.rows(idx).every(function(rowIdx) {
                var selected = dt.row(rowIdx, {selected: true}).any();
                var checkBox = $('input', this.node());
                checkBox.prop("checked", selected);
            });
        });
    

    Colin

  • valredrvalredr Posts: 21Questions: 7Answers: 0
    edited October 2021

    Hi @colin ,
    Thank you so much for this you are truly a life saver and a magician.
    Appreciate the effort :)

Sign In or Register to comment.