mercredi 21 avril 2021

checkbox not working in jquery Datatables row grouping

I have a datatable in which I apply row grouping to it. Also added checkbox control .i want to update row data of which checkbox is checked on button "btnupdate" clicked event,The api does grouping for the column 2 and when i checked the first checkboxes then my code is working but whenever i checked the last checkbox of any group it doesn't work. I've tried the code for grouping listed on the datatables website.The code I used for the button click event is shown below:

 //CODE FOR ROW GROUPING
     var groupColumn = 2;

        datatable1= $('#tblDemo').dataTable({
                 "pageLength": 25,
                 "displayStart": 25,
                 'length': 50,
                 "sScrollY": 260,
                 "sScrollX": "100%",                 
                  "columnDefs": [
                      { "visible": false, "targets": groupColumn }
                  ],
                  "order": [[groupColumn, 'asc']],
                  "displayLength": 25,
                  "drawCallback": function (settings) {
                      var api = this.api();
                      var rows = api.rows({ page: 'current' }).nodes();
                     var last = null;

                      api.column(groupColumn, { page: 'current' }).data().each(function (group, i) {
                        //  debugger;
                          if (last !== group) {
                              $(rows).eq(i).before(
                                  '<tr class="group"><td colspan="10">' + group + '</td></tr>'

                              );

                              last = group;
                          }
                      });
                  }
             });

//CODE FOR BUTTON CLICK FOR CHECKED/SELECTED ROW UPDATION

    $('#btnupdate').on("click",function () {
    
     var rows1;
     var itemDetails = new Array();
  
     rows1 = datatable1.find('tr:not(:hidden)');
     var temp,cnt;
     for (var i = 0; i < (rows1.length - 1); i++) {           
         var arr1 = new Array();            
         if ($("#chkbx" + i ).is(':checked')) {   ///chkbx is a id for checkboxes upto row count 
           
             temp = $.trim($("#txtSQty" + i ).val());
           
                 if (temp == arrQty[i]) {
                     arr1[0] = 'S'
                 }
                 else {
                     arr1[0] = 'M'
                 }
                 arr1[1] = temp
                 arr1[2] = arrPONo[i]    
                
                 itemDetails.push(arr1);
                 cnt = 0;                 
         }                         
     }
     if (cnt == 0) {
        
             --code for update row details--
             }      
    
     return false
 });

`

//arrPONo[i] ,arrQty[i] having the values in datatable colums,which fetch from database and stored in array

Could anyone help me with this? Thanks in advance.




Aucun commentaire:

Enregistrer un commentaire