jQWidgets Forums

Forum Replies Created

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts

  • michal.husak
    Participant

    I’ve found out that this also doesn’t work for some special cases of selected rows.

    But this code seems to work:

    deleteButton.click(function (event) {
       // get the indexes of the selected rows.
       var selectedrowindexes = $("#jqxgrid").jqxGrid('getselectedrowindexes');
       var rowscount = $("#jqxgrid").jqxGrid('getdatainformation').rowscount;
       var arrayOfSelectedIds = [];
       // begin update. Stops the Grid's rendering.
       $("#jqxgrid").jqxGrid('beginupdate');
       selectedrowindexes.sort();
       // delete the selected rows by using the 'deleterow' method of jqxGrid.
       for (var m = 0; m < selectedrowindexes.length; m++) {
          var selectedrowindex = selectedrowindexes[selectedrowindexes.length - m - 1];
          if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
             var id = $("#jqxgrid").jqxGrid('getrowid', selectedrowindex);
             arrayOfSelectedIds.push(id);
          }
       }
       $("#jqxgrid").jqxGrid('deleterow', arrayOfSelectedIds);
       // end update. Resume the Grid's rendering.
       $("#jqxgrid").jqxGrid('endupdate');
    });
    

    michal.husak
    Participant

    Hi ben25,

    I know it’s quite late for the answer, but I’m struggled with the same problem and I can’t see any effort to solve this problem from the jQWidgets Team.

    Your code:

    
    deleteButton.click(function (event) {
       // get the indexes of the selected rows.
       var selectedrowindexes = $("#jqxgrid").jqxGrid('getselectedrowindexes');
       var rowscount = $("#jqxgrid").jqxGrid('getdatainformation').rowscount;
       // begin update. Stops the Grid's rendering.
       $("#jqxgrid").jqxGrid('beginupdate');
       selectedrowindexes.sort();
       // delete the selected rows by using the 'deleterow' method of jqxGrid.
       for (var m = 0; m < selectedrowindexes.length; m++) {
          var selectedrowindex = selectedrowindexes[selectedrowindexes.length - m - 1];
          if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
             var id = $("#jqxgrid").jqxGrid('getrowid', selectedrowindex);
             $("#jqxgrid").jqxGrid('deleterow', id);
          }
       }
       // end update. Resume the Grid's rendering.
       $("#jqxgrid").jqxGrid('endupdate');
    });
    

    is actually good. Only problem is that the array selectedrowindexes changes when you call $("#jqxgrid").jqxGrid('deleterow', id);. So you need to create a copy of the $("#jqxgrid").jqxGrid('getselectedrowindexes'); and save it to the selectedrowindexes variable.

    Best regards

    Michal

Viewing 2 posts - 1 through 2 (of 2 total)