How to display the column headers and column names dynamically in grid using array.
var commonList = [];
var columns = [];
var firstList = [{ "text": "Id ", "datafield": "id"},
{ "text": "Name", "datafield": "name"}];
var secondList = [{ "text": "Second Id ", "datafield": "id"},
{ "text": "Second Name", "datafield": "name"}];
SampleService.setParameter = function(pageFrom){
columns = new Array();
if(pageFrom=="First") {
commonList = firstList ;
}else if (pageFrom=="Second"){
commonList = SecondList;
}
for (var i = 0; i < commonList.length; i++) {
columns.push({ text: commonList[i].text, datafield: commonList[i].datafield });
}
}
SampleService.SampleSource = {
datatype: "json",
datafields: [
{name:'id'},
{name:'name'}
]
};
SampleService.SampleAdapter = new $.jqx.dataAdapter(SampleService.SampleSource);
SampleService.SampleGrid = {
width : '99.8%',
autoheight: true,
showheader : true,
columnsheight : 30,
columnsreorder : true,
source : SampleService.SampleAdapter,
columns : columns
};
Please help.