views:

656

answers:

2

Scenario:

I have three columns in my grid but only one is editable, the other two are filled in on the server side. I am using the built in add functionality of jqGrid and NOT refreshing the grid on successfully add. I would like to have the row added to the grid, like it does automatically, but would like to add it myself because it only adds the one column that is marked 'editable'. I cannot seem to find a way to block the row from being automatically added to the grid, or a way to override the built in add functionality in the grid. My idea was to add the row myself because I will have received back the full row of data back on my submit.

Questions:

  1. Is there a way to stop the grid from automatically adding the row when I do not want a grid refresh, so that I can manually add all the data for the row?

  2. Is it possible to use the built in add button and override the onClick, without digging and and directly figuring out what jqGrid calls the button?

  3. Any better ideas on how to accomplish getting the row added to the grid from the server side without doing it all manually...ie. create my own add button, and popup a dialog and handle all the submit functionality?

EDIT

What would help is if I could stop the grid from auto adding the row...I can deal with doing it myself.

A: 

Here's one solution. Use event afterComplete described here.

afterComplete : function (response, postdata, formid) {…}

In this event, you get the response data from the server. Since the row is already updated/inserted, you can use the response data to update additional row cells. You can probably get row id from postdata, if not, use afterSubmit event - it will allow you to tell jqGrid what is the new row id (once again from the server response), and thus you'll know the value.

queen3
there is no way to just not have jqGrid auto add the row? I have overridden the success event on the ajax submit call to get the data back, and just want write the one line to append the row to the grid...but the row was already added.
CSharpAtl
A: 

Not strictly the answer you want, but I chose to simply bind a onClick event to a button and add the row in that fashion.

var dummyRow;  // you can trick the addRowData method into simply adding a row without 
               // index by passing an undefined value.

jQuery('#addRow').click( function () {
    jQuery('#grid').jqGrid('addRowData', dummyRow, {"name":"New Name","val":"","other":"No"});
});

I'm eager to see if someone else has another option because it seems ridiculous to require the Add Row method of Navigator to be exclusively for ajax calls.

Erik