PDA

View Full Version : Grid columns not sortable?



petzlux
16 Sep 2009, 6:06 AM
Hi
I have a asp page which is returning XML records. I have no control over the format of the XML. Also, the fields per record returned will be variable. So I needed to write some parser to create for each returned XML the appropriate XMLReader and ColumnModel.

I have got it working now fine so that the results are processed and displayed, but when the user tries to sort one of the columns , nothing happens. I have set the default settings to allow sorting, so why doesnt this work ?

A working example can be found here: http://dl.getdropbox.com/u/378590/TLSDSS/manifold_webclient/extGridExample.html (http://dl.getdropbox.com/u/378590/TLSDSS/manifold_webclient/extGridExample.html#)




Ext.onReady(function(){

var queryTable = new Ext.grid.GridPanel({
id: 'queryTable',
store: new Ext.data.Store({
id: 'queryStore'
}),
frame: false,
stripeRows: true,
colModel: new Ext.grid.ColumnModel({
columns: [{
header: 'ID',
dataIndex: 'ID'
}]
})
});

var queryWindow = new Ext.Window({
title: 'Query Results',
width: 400,
height: 250,
layout: 'fit',
id: 'queryWindow',
items: queryTable
});
queryWindow.show();

var conn = new Ext.data.Connection();
conn.request({
url: 'test.xml',
method: 'GET',

success: function(response){
var dq = Ext.DomQuery;
xml = response.responseXML;
recordDef = new Array();
columnDef = new Array();

record = dq.select('item:first cell', xml);

for (var i = 0; i < record.length; i++) {
recordDef[i] = new Object();

recordDef[i].name = record[i].attributes[0].value;
recordDef[i].mapping = "cell[@name=\'" + record[i].attributes[0].value + "\']@value";

columnDef[i] = new Object();
columnDef[i].header = record[i].attributes[0].value;
columnDef[i].dataIndex = record[i].attributes[0].value;

var intrinsic = new RegExp("(I)");
if (intrinsic.test(record[i].attributes[0].value)) {
columnDef[i].hidden = true;
}
}
var XMLreader = new Ext.data.XmlReader({
record: 'item',
id: "cell[@name='ID']@value"
}, recordDef);

queryTable.store.reader = XMLreader;

var colModel = new Ext.grid.ColumnModel({
defaults: {
width: 100,
sortable: true
},
columns: columnDef
})
queryTable.reconfigure(queryTable.store, colModel);

queryTable.store.loadData(xml);
},
failure: function(){
Ext.Msg.alert('Status', 'Unable to get state');
}
});

});

2 Oct 2009, 6:46 AM
your link is broken.