PDA

View Full Version : Distinct rows from an Ext.data.XmlStore?? (Extjs 3.3.0 lib)



dhilchrist
5 Jul 2012, 11:05 AM
Distinct rows from an Ext.data.XmlStore??

Distinct rows from an Ext.data.XmlStore?? (Extjs 3.3.0 lib)

how can I retrieve distinct rows from an XmlStore,

Data Set
Job operation RunId Status
a launch 123 Pass
a lunch 123 Pass
a hold 124 Wait
a hold 124 wait

Result set,
I wanted to display only 2 rows based on RunId

a launch 123 Pass
a hold 124 wait

scottmartin
11 Jul 2012, 4:36 PM
You could filter the rows as they come in .. load event



Ext.onReady(function() {

var store = Ext.create('Ext.data.Store', {
storeId: 'simpsonsStore',
fields: ['name', 'email', 'change'],
data: {
'items': [{
'name': 'Lisa',
"email": "lisa@simpsons.com",
"change": 100
}, {
'name': 'Bart',
"email": "bart@simpsons.com",
"change": -20
}, {
'name': 'Bart',
"email": "otherbart@simpsons.com",
"change": -20
}, {
'name': 'Homer',
"email": "home@simpsons.com",
"change": 23
}, {
'name': 'Homer',
"email": "home@simpsons.com",
"change": 23
}, {
'name': 'Marge',
"email": "marge@simpsons.com",
"change": -11
}]
},
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'items'
}
},

listeners: {
load: function(store){

var uniqueValue = '';
store.filter( // filter unique names
{
filterFn: function(item) {
var name = item.get('name');
if (uniqueValue !== name) {
uniqueValue = name;
return true;
} return false;
}
});


}
}
});

Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [{
header: 'Name',
dataIndex: 'name'
}, {
header: 'Email',
dataIndex: 'email',
flex: 1
}, {
header: 'Change',
dataIndex: 'change',
tdCls: 'x-change-cell'
}],
height: 200,
width: 400,
renderTo: Ext.getBody()
});

});


Regards,
Scott.