Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_Related Related Topics sp_TopicIcon
Added row disappears when edited or grid is sorted on a loadonce:true grid
09/08/2013
18:08
Avatar
lili5058
Member
Members
Forum Posts: 7
Member Since:
09/08/2013
sp_UserOfflineSmall Offline

I have a jqGrid is set to loadonce:true, datatype:'json', because I have fewer than 500 rows, I want to do paging/sorting completely on the client.

I use form editing to both add and edit new rows.

When I create a new row, I have the user select an existing one, because server-side I am making a copy of an existing record and setting a few fields differently. The server returns the new json object which contains the new id and all the data. In the afterSubmit handler I return the new id per the docs.

Here is the code that creates a new row:

                  billGrid.jqGrid('editGridRow', "new",
                      {    editCaption:'New Split Billing',
                          viewPagerButtons:false,
                          url:"${createLink(controller:'billableServiceItem', action:'createSplitBilling')}",
                        beforeShowForm : function(formId){
                            $("#CI_NAME").val(selRowData.CI_NAME);
                        },
                        onclickSubmit: function(){
                            return {origId:selRowId};
                        },
                        closeAfterAdd:true,
                        reloadAfterSubmit:false,
                        afterSubmit : handleRowSaved, // see the handleRowSaved callback function below
                        afterComplete: function(jqResp){  // after adding populate the row with data returned from the server
                            var splitBilling =  jQuery.parseJSON(jqResp.responseText);
                            billGrid.setRowData(splitBilling.id, splitBilling.cell);
                        }
                      }
                  );

              function handleRowSaved(jqResp, postdata){ // this is the afterSubmit callback function
                  var success, message, id;
                  if (jqResp.statusText == "OK"){
                      var returnedBilling = jQuery.parseJSON(jqResp.responseText);
                      success = true;
                      id = returnedBilling.id;
                      if (postdata.id != "_empty"){ //this executes for existing rows
                          billGrid.setRowData(returnedBilling.id, returnedBilling.cell); //after editing, populate the row with returned data
                    }                  
                } else {
                      success = false;
                      message = "An Error occurred: " + jqResp.statusText;
                  }              
                  return [success, message, id];   // returning the id, per the docs
            };

After creating the new row it appears as the first row in the grid and I can see by looking at the _index that it occupies that last position in the index, with the new id in place.

All fine a good ...  but if I sort the grid the row disappears (again, loadonce is set to true)

Also if I edit the new row, it disappears after the response is received and I try to populate the row with the returned data. While debugging, I can see the the data visually changes, but as soon as the afterSubmit handler (my 'handleRowSaved' method) returns, the row disappears.

Any suggestions on how to add a row and not lose it?

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
32 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information