vivek
vivek

Reputation: 1

adding values to a row in jqgrid

I am using ajax function to call a method on server side which will return a set of values, I need to add these values to the next row of a jqgrid. How to insert values to a jqid by iterating the rownumber?

Upvotes: 0

Views: 3428

Answers (1)

Oleg
Oleg

Reputation: 221997

After you receive the data from the the server you can add there to the grid. For example, if your grid has colModel with column names 'invid','invdate','amount','tax','total','note'. The code which add the row could be about following

var myfirstrow = {invid:"1", invdate:"2007-10-01", note:"note",
                  amount:"200.00", tax:"10.00", total:"210.00"};
$("#grid_id").jqGrid("addRowData","1", myfirstrow);

where "1" is the id of the data which you want to add.

If you want to add data to a special position in the grid, for example, after the selected row you can do almost the same:

var grid = $("#grid_id");
var selRowId=grid.jqGrid('getGridParam','selrow');
var myData = {invid:"1", invdate:"2007-10-01", note:"note",
                  amount:"200.00", tax:"10.00", total:"210.00"};
grid.jqGrid("addRowData", "1", myData, "after", selRowId);

See Data Manipulation part of the jqGrid documentation. By the way with respect of addRowData method you can add many rows to a grid at one call. In the case the data parameter must be array of row data.

Upvotes: 1

Related Questions