tags:

views:

1091

answers:

5

I am facing an issue while making a common grid control.

When I put

colModel:[ {name:"ID", index: "ID", width: 400, align: "Left"},{name:"Description", index: "Description", width: 400, align: "Left"}], It works.

When I am trying to replace the ColModel by a string variable I am not getting right display. colModel:[ColDisplay],

The problem is the following. When we put a string variable it comes like the following (with starting ending ‘) ‘{name:"ID", index: "ID", width: 400, align: "Left"},{name:"Description", index: "Description", width: 400, align: "Left"}’

If you put colModel:[ ‘{name:"ID", index: "ID", width: 400, align: "Left"},{name:"Description", index: "Description", width: 400, align: "Left"}’],

It is not able to understand the Columns.

Any solutions for this.

+1  A: 
  1. Try eval("([" + ColModel + "])")
  2. Get FireBug
queen3
ColModel = '{name:"ID", index: "ID", width: 400, align: "Left"},{name:"Description", index: "Description", width: 400, align: "Left"}'; My ColModel string is as above and added it as below to the jQuery.colModel:[eval("(" + ColModel + ")")],Only one column is getting displayed.
Thank you so much... It worked!!!
A: 

I tried colModel:[eval("(" + ColModel + ")")],

It displayed only one column.

A: 

ColModel = '{name:"ID", index: "ID", width: 400, align: "Left"},{name:"Description", index: "Description", width: 400, align: "Left"}'; My ColModel string is as above and added it as below to the jQuery.

colModel:[eval("(" + ColModel + ")")],

Try the new one (array [] inside eval - see my edited answer). And you have to understand that string is a black box to the compiler - your "colModel:[ ‘{" is _COMPLETELY_ wrong because you make array content a single string.
queen3
A: 

The [] indicate that its is an array.

Try this

var ColModel = [{name:"ID", index: "ID", width: 400, align: "Left"},{name:"Description", index: "Description", width: 400, align: "Left"}]

$("#gridid").jqGrid({
~
colModel:ColModel
~});
Vinodh Ramasubramanian
Tried this... not working.
A: 

Hi I have same problem, but when i change colModel, i get nothing.

I load one JqGrid when page created and i have one select listbox, when user select another item in that list, i want keep that JqGrid then dynamically change colmodel of that jqgrid and call "trigger(reloadGrid)".

In the theory it must work because i use api setGridParam method of jqGrid, only thing that i can't find is reverse method of GridUnload().

I used these lines of code:

// Sample col model var secondColModel = [{name:"myname",index:"myIndex",width:40, align:"left"}]; $('#mygrid').setGridParam({colModel: secondColModel});

I used every thing like eval...

but they did not work. Please help me ASAP.

My boss is going to kill me.