PDA

View Full Version : Want to Exclude Null values while Sorting.



manishnp
1 Oct 2013, 6:20 AM
Hi Experts,


While Searching for sorting functionality where null values to be at bottom I found this.
<CODE>
select *
from MyTable
order by ISNULL(MyField,1) DESC,
MyField asc;
</CODE>

It is giving the proper resultset. Now I want to achieve the same sorting functionality in our lovely ExtJS.

So OnLoad it will load the resultset by keeping the null values at bottom and again when the column is clicked for sorting in the Grid it will follow the same rules.

I tried to make it work.Can somebody put a light on this piece of code.


<CODE>
Ext.onReady(function () {
var store = Ext.create('Ext.data.Store', {
storeId: 'simpsonsStore',
fields: ['name', 'email', 'phone'],
remoteSort: false,
data: {
'items': [{
'name': 'Lisa',
"email": "lisa@simpsons.com",
"phone": "555-111-1224"
}, {
'name': 'Lisa',
"email": "bart@simpsons.com",
"phone": "555-222-1234"
}, {
'name': 'Homer',
"email": "home@simpsons.com",
"phone": "555-222-1244"
}, {
'name': 'Marge',
"email": "marge@simpsons.com",
"phone": "555-222-1254"
},

{
'name': '',
"email": "",
"phone": ""
}]
},
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'items'
}
}

});


Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: store,
columns: [{
text: 'Name',
dataIndex: 'name'
}, {
text: 'Email',
dataIndex: 'email',
flex: 1
}, {
text: 'Phone',
dataIndex: 'phone'
}],
renderTo: Ext.getBody(),
listeners:
{
'afterrender': function()
{
store.sort([
{
property : 'name',
direction: 'DESC'
},
{
property : 'name',
direction: 'ASC'
}
]);
}
}
});
});
</CODE>

Thanks
Manish Pandit

ettavolt
1 Oct 2013, 10:29 PM
Take a look on transform (http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.util.Sorter-cfg-transform) cfg for sorter.