0

I'm having a problem with regards to JQgrid.

here is my code for my grid. i'm using clientsideevents of "beforerowselect" and "loadcomplete"
note: i'm using load complete for the reload of the grid
everytime the grid reloads it will select the item.

<trirand:JQGrid ID="jqgrid" runat="server" Height="475px" Width="1510px" MultiSelect="false" ShrinkToFit="true" AutoWidth="true">
<ClientSideEvents BeforeRowSelect="beforeSelect" LoadComplete="loadComplete"/>


In "beforeselectevent" what i do here is to get the cellvalue of
the rowid of "itemid".

I tried to create a session variable to store the value of the "ItemID" and store it in the var sessionItemID for me to be able to pass it on "load complete event".

Problem: but everytime i tried to insert breakpoint here it always gives me '' value.

function beforeSelect(rowid, e) {
                grid = $("#<%= jqgrid.ClientID %>");
                ItemID = grid.jqGrid('getCell', rowid, 'ItemID');
                var sessionItemID = '<%=Session["ItemID"] %>';
}


here in "loadcomplete" event. I passed the sessionItemID so that i can get the ItemID. so everytime i update the item on the grid.
it will reload the page and select the item that i updated.

Problem: after it reloads, it doesn't select the item after it reloads.

function loadComplete(sessionItemID ) {
                if (ItemID != 0 || ItemID != null) {
                    grid = $("#<%= jqgrid.ClientID %>");
                    grid.trigger("reloadgrid");
                    grid.jqgrid('setselection', "2" );
                }
            }

what i want to achieve is this (to make the story short)
1. select row on the grid, form will pop-up then update record.
2. after updating record the user will save the page then close.
3. grid will reload
4. it will remember the selected/updated item.

I'm really confused on what will i do next. Thanks

StackOverflowUser
  • 305
  • 3
  • 8
  • 19

2 Answers2

1

I think you have some spelling mistakes in your method names,

change grid.jqgrid('setselection', "2" ); to grid.jqGrid('setSelection', "2" );

2 changes jqgrid to jqGrid and setselection to setSelection

UPDATE : if it is to retain the selection after update you can achieve this by current:true in reloadgrid

Remove the code in loadComplete and add it to aftersaveFunc like given below

                    grid = $("#<%= jqgrid.ClientID %>");
                    grid.trigger("reloadGrid",[{current:true}]);

Please note the reloadGrid is camel case (G is upper)

Kris
  • 1,882
  • 1
  • 20
  • 23
0

To solve the described problem you can try to use reloadAfterSubmit: false option of form editing to prevent reloading of the grid st the end of row editing. If you don't add new rows the option could be the best way.

Alternatively you can use afterSubmit callback or jqGridAddEditAfterSubmit event to save current selection and restore it after the text loading of the grid. The corresponding code could be about the following:

$("#jqgrid").bind("jqGridAddEditAfterSubmit", function () {
    this.grid.selectionPreserver(this);
});
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • hi @oleg, I tried to use this code on my program and it works. http://stackoverflow.com/questions/6881717/how-to-highlight-the-last-selected-row-after-client-side-sorting-on-jqgrid – StackOverflowUser Apr 18 '13 at 03:15
  • but I want to add some feature which is the positioning the scroll bar, For example. I have 500 row, if I click on 250th suppose the position of the scroll bar is on the middle. I want it also to set the position where the selected item is. Can you help me with this? – StackOverflowUser Apr 18 '13 at 03:17
  • hi @Oleg can you help me with this? http://stackoverflow.com/questions/16142993/getting-the-sum-using-footerdata – StackOverflowUser Apr 23 '13 at 00:14