views:

118

answers:

3

i wrote this script

$.getJSON('<%=Url.Action("JsonSave","Controler")%>',
            { id: newRow.Id, personId: newRow.PesronId},
             function(data) {
                 $('#grid').trigger('reloadGrid'); //{0}
                 $('#grid').editRow(rowCount); //{1}
             })

what should i do so that {1} would be executed exactly after {0}

+3  A: 

ANSWER UPDATED I did a little research, and it seems you are using the jQuery Grid plugin. It has a callback called gridComplete that should do what you need. Combine that with my original answer to use one and you will be all set:

Since events are called in order, you could add your method into the event queue like this:

$.getJSON('<%=Url.Action("JsonSave","Controler")%>',
        { id: newRow.Id, personId: newRow.PesronId},
         function(data) {
            $('#grid').one('gridComplete', function(){ $('#grid').editRow(rowCount); });
            $('#grid').trigger('reloadGrid');
         })

Using the one instead of bind causes your event callback to be used only once.

Doug Neiner
thanks for the update, i tried it but still no result, im gettin realy confused
CoffeeCode
A: 

Are trigger() and editRow() asynchronous calls? If so, you may be out of luck doing it this way, as you don't know when they will be called.

If you need editRow() to be called after trigger() completes, make the call to EditRow() at the end of the trigger() function itself.

darren
+1  A: 

Doug's answer is right except the event to be used is loadComplete

jQGrid documentation for events

Vinodh Ramasubramanian
@Vinodh, from the event list it seems that `loadComplete` fires after the XHR request returns, but before the Grid is updated. His call to edit the row would fail because it would be updated after the event ended. `gridComplete` is the correct event AFAIK.
Doug Neiner
In my experience of using jqGrid, I have always seen `loadComplete` execute after `gridComplete`. Not sure of the reason. But for the purpose of this discussion I tested the call to `editRow` and it works whether it is placed in `gridComplete` or `loadComplete` events.
Vinodh Ramasubramanian