Arun C
Arun C

Reputation: 49

Add Columns Properties in JQGrid from array

I have an array which contains following elements.

var column = { };
column["name"] = "Id";
column["sorttype"] = 'int';
column["hidden"] = true;
column["editable"] = false;
arr1.push(column);

column["name"] = "Name";
column["sorttype"] = 'string';
column["hidden"] = false;
column["editable"] = true;
arr1.push(column);

column["name"] = "Age";
column["sorttype"] = 'int';
column["hidden"] = false;
column["editable"] = true;
arr1.push(column);

column["name"] = "Address";
column["sorttype"] = 'string';
column["hidden"] = false;
column["editable"] = true;
arr1.push(column);

Also have a jqgrid. Which use the columns exactly same as arr1

$("#grid").jqGrid({ //set your grid id
    datatype: "local",
    colNames: s,
    colModel: [{
        name: 'id',
        index: 'id',
        sorttype: 'int',
        hidden:true ,
        editable: false,
    }, {
        name: 'Name',
        index: 'Name',
        editable: false?, 
    }, {
        name: 'Age',
        index: 'Age',
        editable: true,
    }, {
        name : 'Address',index :'Address'
        sortable:true,
        editable:true,
    },
});

I want to replace the colModel from Jqgrid by arr1. Is it possible please help

Upvotes: 2

Views: 884

Answers (2)

Arun C
Arun C

Reputation: 49

I add column["index"] and push to arr1 then replace the code by $("#grid").jqGrid({ //set your grid id datatype: "local", colNames: s, colModel: arr1 });

It is worked

Upvotes: 1

Kiran Reddy
Kiran Reddy

Reputation: 556

Yes, you just have to replace the colModel array with arr1

$("#grid").jqGrid({ //set your grid id
    datatype: "local",
    colNames: s,
    colModel: arr1
});

Upvotes: 1

Related Questions