Reputation: 117
guys i want the column names to be dinamic in case it is changed so i dont have to put it namually .. here is my code
jqGrid11.prototype = {
display : function() {
$('body').append(this.html.join(""));
$("#jqGrid").jqGrid({
url : "index.jsp",
colModel : [ {
label : 'Department Name',
name : 'Department Name ',
width : 200
}, {
label : 'id',
name : 'id',
key : true,
width : 200
}, {
label : 'Employees',
name : 'Employees ',
width : 500
} ],
viewrecords : true,
width : 780,
height : 250,
rowNum : 20,
pager : "#jqGridPager"
});
for (var i = 0; i < this.data.length; i++) {
$("#jqGrid").jqGrid("addRowData", i + 1, this.data[i]);
}
}
};
so i want the department name and id and employee to be generated dynamically
Upvotes: 0
Views: 358
Reputation: 222017
You should never ever use name
property of colModel
, which contains spaces. The name
will be used to construct ids of some elements and spaces are prohibited by HTML5
for ids.
You should never ever fill the grid using addRowData
in the loop. It's the slowest way to fill the grid.
You use url : "index.jsp"
without specifying datatype
. It defaults to use datatype: "xml"
. On the other hand, you wrote that you want to use JSON as input.
If you have input data as array of items (this.data
) then you should use datatype: "local", data: this.data
, which will create jqGrid with the data and display the first page of the data (base on rowNum: 20
).
I'd recommend you to verify which version of jqGrid and from which fork of jqGrid you use. I recommend you to use free jqGrid 4.13.2 - the current version of free jqGrid fork, which I develop.
Upvotes: 1