To add a row to JQGrid, you can use the addRowData
method. Here is an example code snippet that demonstrates how to add a row to JQGrid:
javascript// Assuming the grid's ID is "myGrid"
var newRowData = {id: "newRow", name: "John Doe", age: 30};
$("#myGrid").jqGrid("addRowData", "newRow", newRowData);
In this example, we create a new row data object with properties id
, name
, and age
. We then use the addRowData
method to add the new row data to the grid with the ID "myGrid"
. The first argument of addRowData
is the ID of the new row, and the second argument is the data object for the new row.
Note that the addRowData
method can also be used to add multiple rows to JQGrid at once. You can pass an array of row data objects as the second argument of the method, like this:
javascript// Assuming the grid's ID is "myGrid"
var newRowsData = [
{id: "newRow1", name: "John Doe", age: 30},
{id: "newRow2", name: "Jane Smith", age: 25},
{id: "newRow3", name: "Bob Johnson", age: 40}
];
$("#myGrid").jqGrid("addRowData", "id", newRowsData);
In this example, we pass an array of three row data objects to the addRowData
method. Each row data object represents a new row to be added to the grid. The id
argument in this case is not used because it is ignored when adding multiple rows at once.
Comments
Post a Comment