2015-05-14 18 views
1

我为了利用内线摆脱电网已经排序的列名使用下面的代码排序的列名JS甚至我的网格(myGrid)正常工作得到已经在Ext JS中电网

function onClick(){ 
    var grid = myGrid.getStore().sortInfo.field; 
    alert("grid") 
} 

我“M收到错误‘对象为空或不是对象’

请帮助

+0

“myGrid”没有在这个函数中定义。也许这是问题所在。 – mfruizs2

+0

myGrid已经在我的程序中定义了,并且屏幕上显示了相同的结果。我只需要在网格中获取短列(ASC \ DESC)的名称。 –

+0

myGrid已经在我的程序中定义,并且同样在屏幕上正确显示。 我需要帮助才能从myGrid上获取已排序列(ASC或DESC)的名称。 –

回答

1

试图解决与煎茶存储功能存储。

煎茶API:sort store

//sort by a single field 
myStore.sort('myField', 'DESC'); 

//sorting by multiple fields 
myStore.sort([{ 
    property : 'age', 
    direction: 'ASC' 
}, { 
    property : 'name', 
    direction: 'DESC' 
}]); 

// Sort the store using the existing sorter set. 
myStore.sort(); 

你的情况:

myGrid.getStore().sort('myField', 'DESC'); 
+0

感谢您的回复,这已经整理:) –

+0

我不觉得答案是有用的。我也希望用于检索当前排序字段的解决方案。 – parkourkarthik

+0

这是@green viper的有用解决方案,也许您需要对代理ajax请求(http://docs.sencha.com/extjs/4.2.3/#!/api/Ext.data.proxy.Ajax)或其他解。创建一个新的线程来公开它。 – mfruizs2

1

我相信这是笔者的意思:

myGrid.getStore().sorters.keys 

它与分类dataIndexes返回数组列。

如果您需要更多然后详细信息:

myGrid.getStore().sorters.items 

是要走的路。它给你一个这样的对象数组: { direction: "ASC", property: "yourDataIndex", root: "data" }