2015-05-14 37 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" }