Author Topic: Delete multiple rows from grid  (Read 5467 times)

Steff

  • Newbie
  • *
  • Posts: 4
    • View Profile
Delete multiple rows from grid
« on: April 04, 2015, 04:13:20 pm »
Hi,

I need to delete multiple rows from grid.

I tried two solution according your references (see below). Unintentionally only the first record in the index array gets deleted from the grid.

Is there a solution for this problem?

Regards

function RemoveRecordsFromGrid(arrRowIndxs)
            {
                alert(arrRowIndxs.join('\n')); // e.g. [0,2]
                if (arrRowIndxs.length != 0)
                { 
                    for (var i = 0; i < arrRowIndxs.length; i++)
                    {
                        //----- Solution 1 ----------
                        $("#grid_rowhover").pqGrid("deleteRow", { rowIndx: arrRowIndxs, track: false });

                        //------ Solution 2 ----------
                        //var DM = $("#grid_rowhover").pqGrid("option", "dataModel");
                        //alert("REmoving row from Grid " + arrRowIndxs);
                        //DM.data.splice(arrRowIndxs, 1);
                        //$("#grid_rowhover").pqGrid("refreshDataAndView");
                        //$("#grid_rowhover").pqGrid("setSelection", { rowIndx: arrRowIndxs });
                    }
                }
                else
                {
                    alert("No Records to Remove");
                }
            }

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6210
    • View Profile
Re: Delete multiple rows from grid
« Reply #1 on: April 06, 2015, 05:28:42 pm »
it would be

Code: [Select]
$("#grid_rowhover").pqGrid("deleteRow", { rowIndx: arrRowIndxs[ i ], track: false });

instead of

Code: [Select]
$("#grid_rowhover").pqGrid("deleteRow", { rowIndx: arrRowIndxs, track: false });

and try to delete them in descending rowIndx [ 2, 0 ] or by rowData reference.

Steff

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Delete multiple rows from grid
« Reply #2 on: April 06, 2015, 06:08:44 pm »
The  rowIndxs.reverse(); did the trick,
and obviously the index must be applied.

this line on its own did not work(I just forgot it in the example):
$("#grid_rowhover").pqGrid("deleteRow", { rowIndx: arrRowIndxs[ i ], track: false });

So thank you very much for your help