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
349
Working with deleted rows and Selected rows in webgrid client side
posted

Hi,

I am working with an ms listbox control and a webgrid, transferring items between the two wholly on the client side. I have run into problems when I move a second row from my webgrid after clicking a button that calls javascript to 'remove this item from the grid and put it in the list box'. This works fine when i select the first grid row , but then an error occurs when I select the next row (previously the second displayed grid row but now appears as the first row). Using the code below I get an error because it is still trying to reference the original row 0 ie grid_r_0 as it remains in the SelectedRows collection.

...initialise grid and listbox object
...
    for(var selectedRowID in oGrid.SelectedRows)
    {
      var oSelectedRow=igtbl_getRowById(selectedRowID);
      var menuItemText = oSelectedRow.getCellFromKey("menuitem").getValue();
      var menuItemID = oSelectedRow.getCellFromKey("menuitemid").getValue();
       //Add back to all items list
       var iCurrentIndex = oAllItemsList.length;
       oAllItemsList.options[iCurrentIndex] = new Option();
       oAllItemsList.options[iCurrentIndex].text = menuItemText;
       oAllItemsList.options[iCurrentIndex].value = menuItemID;
       oAllItemsList.options[iCurrentIndex].selected = true;

      //delete row from grid
      igtbl_deleteRow(gridName,oSelectedRow.Id);          
    }
    oGrid.clearSelectionAll();

Questions I have and would appreciate any feedback on are:

  1. Is there a way to clear the SelectedRows collection client side?this is seems enough server side as it is a collection
  2. When I delete a webgrid row it is then present in the deletedRows collection. Does this mean that row grid_r_0 is always not available until a postback? is there a quick way to refresh the rows client side so that row grid_r_1 becomes grid_r_0 and so on?

Incidentally the reason why I am doing this is because I want to have the ability to move rows up and down in the webgrid, so the user can specify the exact sequence of items in the grid. I have extended the KB article KB05596 "HOWTO:move a row to top or bottom of grid" to do this.

thanks very much for feedback

David

 

  • 3475
    Offline posted

    David,

    I know you posted this a long time ago but do you remember how you got around this problem.  I am having the issue where I sort (either client-side or server-side), then delete a selected row and then my client-side SelectedRows collection still contains the previously deleted selected rows.  This messes up the next delete process and the user ends up deleting rows they did not select.  Thanks for your help.