PDA

View Full Version : building a column model manually in javascript



jonesmc123
24 Nov 2007, 7:19 AM
assuming I get the right json back from a call to a python based module, how would I build a new column model in javascript for a ext.js grid?

as in a result of something like this
cm: new xg.ColumnModel([
new xg.RowNumberer(),
{header: "Price", width: 20, sortable: true, dataIndex: 'price'},
{header: "Change", width: 20, sortable: true, dataIndex: 'change'},
{header: "% Change", width: 20, sortable: true, dataIndex: 'pctChange'},
{header: "Last Updated", width: 20, sortable: true, dataIndex: 'lastChange'}
]),


but built by iterating over a JSON object returned from my python server code. I'm not a javascript master and I'm new to ext.js so please be kind :)

hendricd
24 Nov 2007, 10:01 AM
Yes, your response could look something like this or even just the header portions:



new Ext.grid.ColumnModel([
new Ext.grid.RowNumberer(),
{header: "Price", width: 20, sortable: true, dataIndex: 'price'},
{header: "Change", width: 20, sortable: true, dataIndex: 'change'},
{header: "% Change", width: 20, sortable: true, dataIndex: 'pctChange'},
{header: "Last Updated", width: 20, sortable: true, dataIndex: 'lastChange'}
])

But, in practice, a smooth-rendering grid will need the columnModel in advance (in its constructor).

If you intend to reset the columnModel periodically(via Ajax request), you'll need to look at the grid.reconfigure method as a lot goes on when re-assign it a new CM.