To add a column to JQGrid, you can use the addColumn
method. Here is an example code snippet that demonstrates how to add a column to JQGrid:
// Assuming the grid's ID is "myGrid"
$("#myGrid").jqGrid("addColumn", {
name: "newColumn",
index: "newColumn",
width: 100,
align: "center",
sortable: true,
formatter: "text",
editable: true
});
In this example, we use the addColumn
method to add a new column to the grid with the properties name
, index
, width
, align
, sortable
, formatter
, and editable
. The name
and index
properties are required, and they define the name and index of the new column, respectively. The other properties are optional and can be used to customize the behavior and appearance of the new column.
Note that when you add a new column to JQGrid, you may also need to update the column model and reload the grid data to ensure that the new column is displayed correctly. You can update the column model using the setColProp
method, and you can reload the grid data using the trigger
method, like this:
javascript// Update column model and reload grid data
$("#myGrid").jqGrid("setColProp", "newColumn", {hidden: false});
$("#myGrid").trigger("reloadGrid");
In this example, we use the setColProp
method to update the hidden
property of the new column, making it visible in the grid. We then use the trigger
method to reload the grid data with the updated column model.
Comments
Post a Comment