jQWidgets Forums
jQuery UI Widgets › Forums › Grid › Create jqGrid Column Dynamically
Tagged: jqgrid
This topic contains 3 replies, has 3 voices, and was last updated by Nagoor 11 years ago.
-
Author
-
Hello Everyone,
i want to create jqGrid column dynamically where my column list come from server in json or xml format.
How can i do it.
Please help me out.HI N_Cool
First u have to make column list into array then create two array one grid column property and another one is dataField array.
Consider the array colDataFieldArray which contain three values [Jan,Feb,Mar];
var gridColumns = [];//Array used store grid column properties
var dataFieldColumns = [];//Array used to store grid column datafield
var colDataFieldArray =[Jan,Feb,Mar]//This is the array which contain your Dynamic column datafields
for(var i=0;i<colDataFieldArray.length;i++){
var colStr = $.trim(colDataFieldArray[i]);
gridColumns.push({ text:”Dynamic Columns Label”, dataField: colStr, align : ‘center’, cellsalign:’right’, width: 50});
dataFieldColumns.push({name:colStr, type: ‘float’});
}
var GridURL =
{
datatype: “json”,
datafields: dataFieldColumns,
cache: false,
url://provied the URL here
};
var dataAdapter = new $.jqx.dataAdapter(GridURL);$(“#JqxGrid”).jqxGrid({
width: 150,
autoheight: true,
source : dataAdapter,
editable : true,
rowsheight: 20,
columnsresize:true,
enabletooltips:true,
verticalscrollbarlargestep: 50,
scrollbarsize: 15,
selectionmode : ‘multiplecellsadvanced’,
columns :gridColumns
});Hello anandbabu,
Thank you for reply it’s help me understanding solution for my problem.
hello anandbabu,
i used your method to create dynamic coloumns. i tried to implement cellserenderer function , but its not working. is there any way to implement cells renderer with dynamically generated coloumns. here is the sample of my code.
gridColumns.push({ text:$.trim(colDataFieldArray[i]), dataField: colStr, cellsrenderer: cellsrenderer , align : ‘center’, cellsalign:’center’, width: 150});
and how can we give different properties for different coloumns i.e, different width for each coloumn. as per your code all coloumns will get same properties, i also want to add hidden coloumns.
pls help..
thanks
-
AuthorPosts
You must be logged in to reply to this topic.