mercredi 15 mars 2017

jQuery datatable checkbox event handling

I have 2 jQuery datatables Table A,Table B on the same page and several dynamically created check boxes in each row for both tables. I am trying to add an event handler to the checkboxes in both tables using common code. Currently when I select Table A-checkbox, the Table B-checkbox is updated as well. This is my code.

    Utility.addCheckboxlistener = function(id,name) {   
        jQuery('input:checkbox').change(
        function(){
                alert(id); --------> I am not getting the correct id here, instead id of the first table added to listener is read
            if (jQuery(this).prop('checked')) {
                //disable buttonA(name)
            }
            else{                   
                //disable buttonB(name)
            }
        });

I tried passing in the checkbox id, but it always reads the id of the first table added to the listener regardless which table event(A or B) is triggered.

How can I separate the checkbox events for both the tables? I am using a combination of jQuery 1.8.2(legacy code) and 1.10.11

Utility.addCheckboxlistener('tblA-chkbox', '#tblA-Button'); -----> listener always reads this id (tblA-chkbox), if I reverse the order, then it reads in tblB-chkbox for both table events.
Utility.addCheckboxlistener('tblB-chkbox', '#tblB-Button');




Aucun commentaire:

Enregistrer un commentaire