0

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

3
  • do you have a source of data for dynamic columns? like http response in JSON array? Commented Apr 13, 2016 at 14:20
  • yes .. i have a json array Commented Apr 13, 2016 at 14:21
  • I think the answer you are looking is something like this - stackoverflow jqgrid-and-dynamic-column-binding Commented Apr 13, 2016 at 14:44

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.