Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
885
deleting multiple rows in client side?
posted

Hi,

       I am using WebDataGrid (vol 12.1) in my project. I basically list the files present in a folder inside the grid. I also have an option to delete single / multiple file(s). When i select and delete a file, i am just hiding that row. All of this is done in client-side. I have enabled Batch Updates

<Behaviors>
<ig:EditingCore AutoCRUD="False" BatchUpdating="True"></ig:EditingCore>
<ig:Selection CellClickAction="Row" RowSelectType="Multiple"></ig:Selection>
</Behaviors>

   I am not able to delete multiple rows at a single go. For example, in the grid i have 7 rows, and i select 3 rows to be deleted and i click on "Del" button. Instead of deleting 3 rows, it is deleting only 1 single row. The code i have written in client-side for "Del" button is shown below

var grid = $find("WebDataGrid1");
var selectedRows = grid.get_behaviors().get_selection().get_selectedRows();

for (var j=0; j< selectedRows.get_length();j++)
{
       grid.get_rows().remove(selectedRows.getItem(j), false);
}

       After clicking on the "Del" button, i am able to get the count as 3. After removing the first row, the selectedRows.get_length() becomes 0. What could be the  problem? Can we delete multiple rows in the grid in client-side? If so How? I am converting my UltraWebGrid to WebDataGrid.

Thanks,
Raja.

Parents
  • 49378
    posted

    Hello cadcame,

    Thank you for posting in the community.

    You can use thedeleteRowfunction of the RowDeleting behavior in order to delete multiple rows while batch updating is enabled. For instance:

     

    Code Snippet
    1. function Button1_onclick() {
    2.     var grid = $find("WebDataGrid1");
    3.     debugger;
    4.     var selectedRows = grid.get_behaviors().get_selection().get_selectedRows();
    5.     var selectedRowArray = [];
    6.     for (i = 0; i < selectedRows.get_length(); i++) {
    7.         selectedRowArray[i] = selectedRows.getItem(i);
    8.     }
    9.     grid.get_behaviors().get_editingCore().get_behaviors().get_rowDeleting().deleteRows(selectedRowArray);
    10.  
    11.     //optional: call commit to update the datasource immediately
    12.     grid.get_behaviors().get_editingCore().commit();
    13. }

    Attached is a small sample illustrating this scenario.

    Please let me know if this helps.

    WebDataGridDeleteMultipleRowsClientSideBatch.zip
Reply Children