jquery – jqGrid – how to add custom properties to a grid – Education Career Blog

How can you add custom properties to a grid?

The properties would not be used by jqGrid itself. It’s more of meta data which would be used by our custom code.

For example, we want a custom property to identify if the grid appears on our ‘main page’. This property would be read by some of our common functions which would handle certain tasks differently depending on if the grid is on the main page.

Can you just do something like:

mygrid.onMainPage = true;

?? Not sure if that is valid JavaScript or would mess up jqGrid somewow.

,

You just add them. Works fine. Try:

$("#myGrid").jqGrid({
    url: "/Data", // usual "standard" properties
    myCustomProperty: "Hi there!"
});

Now you can access them:

var mcp = $("#myGrid").jqGrid("getGridParam", "myCustomProperty");

For a real-world example, look at my jqGrid.history plugin.

,

You should look into jQuery .Data

http://api.jquery.com/jQuery.data/

Leave a Comment