PDA

View Full Version : Sorting in grid on basis of two fields.



Neha Sodhi
16 Jan 2011, 11:38 PM
I have a grid having two fields, newsdate and newstime, and use a single column to render both, now I want to sort this grid on basis of date and time both, where as currently ext js sorts it on basis of date only.


var readerNewsLatest = new Ext.data.JsonReader( {
root : 'response.data.newslist.news'

}, [
{name : 'cocode', type : 'string'},
{name : 'newsdate', type : 'string'},
{name : 'newstime', type : 'string'},
{name : 'heading', type : 'string'},
{name : 'captions', type : 'string'},
{name : 'arttext', type : 'string'}
]
);

var dtStartDate = new Date(new Date().valueOf()-(60*(24*60*60*1000)));
var sStartDate = fNewsGetDDNumber(dtStartDate.getMonth()-1)+"-"+fNewsGetDDNumber(dtStartDate.getDate())+"-"+dtStartDate.getFullYear();
var respLatestNews=ajaxFunction("GET",'${mktNewsMoreLatestResURL}&actionid='+pageActionIdNewsMoreLatest+'&fromdate='+sStartDate+'&recordcount='+globalRowCount,false);
var jsonLatestNews=Ext.util.JSON.decode(respLatestNews);
var storeLatest = new Ext.data.Store( {
reader : readerNewsLatest,
proxy: new Ext.ux.data.PagingMemoryProxy(jsonLatestNews),
listeners : {
'load' : function(store) {
var iTotalCount=store.getTotalCount();
}, 'exception' : function(dp, type, action) {
this.removeAll();

}}
});
var tbNewsLatestPaging = new Ext.PagingToolbar({
store: storeLatest,
pageSize:5,
displayInfo: true,
forceFit:true,
doRefresh:function(){
nCurrentCursorLatest = this.cursor;
respLatestNews=ajaxFunction("GET",'${mktNewsMoreLatestResURL}&actionid='+pageActionIdNewsMoreLatest+'&fromdate='+sStartDate+'&recordcount='+globalRowCount,false);
jsonLatestNews=Ext.util.JSON.decode(respLatestNews);
gridLatestNews.getStore().removeAll();
gridLatestNews.getStore().proxy= new Ext.ux.data.PagingMemoryProxy(jsonLatestNews);
gridLatestNews.getStore().load({params:{start:nCurrentCursorLatest, limit:5}});
}
});

?
function rndNewsTime(value, meta, record, rowIndex, colIndex, store) {
return String(record.get("newsdate")).substring(0,String(record.get("newsdate")).lastIndexOf("-")).replace(/-/g,' ')+", "+value;
}
function rndNewsURL(value, meta, record, rowIndex, colIndex, store) {
return '<div><span style=\"cursor:pointer\">' + ((String(value).length>55)?(String(value).substring(0,55)+'...'):(value)) + '</span></div>';
}
function fGetSortedTime(value, meta, record, rowIndex, colIndex, store){
var sDate = String(record.get("newsdate"));
var sTime = String(record.get("newstime"));
var testMonth = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
var dateMonth;
for(i=0;i<12;i++){
if(testMonth[i]==(sDate.substr(3,3))){
dateMonth = i+1;
}
}
var dateYear =sDate.substr(7,4);
var dateDate = sDate.substr(0,2);
var timeHOUR = sTime.substr(0,2);
var timeMinute = sTime.substr(3,2);
finalDate = new Date(dateYear,dateMonth-1,dateDate,timeHOUR,timeMinute,0);
//alert(finalDate);

return finalDate.getTime();
};

var cmNewsMoreLatest = new Ext.grid.ColumnModel( {
columns : [ {
width : 58,
dataIndex : 'newstime',

multipleSortInfo: [{field: 'newsdate', direction:'DESC'}, {field: 'newstime', direction:'DESC'}],
sortable:true,
renderer:rndNewsTime

}, {
width : 200,
dataIndex : 'heading',
renderer: rndNewsURL
}
]
});

Condor
16 Jan 2011, 11:44 PM
1. It's multiSortInfo and not multipleSortInfo.
2. multiSortInfo is a config option of the store and not of the columnmodel.

ps. I recommend using PagingStore instead of PagingMemoryProxy.

Neha Sodhi
17 Jan 2011, 1:14 AM
Is it necessary to use pagingStore instead of pagingmemoryProxy for sorting...???
I used multistoreinfo in store but it is still niot working there..

Can you suggest any way by which I can do that...