2010-01-24 69 views
0

我正在使用dojo.data.ItemFileWriteStore來繪製一個dojo datagrid(它工作正常),並顯示正確的網格。我正在使用客戶端排序,這也正常工作。 但現在我需要改變排序和做服務器端。爲此,我想使用onHeaderCellClick事件,使用它我能夠運行JavaScript函數.. 像dojo datagrid自定義排序服務器端

gridInfo = { 
      store: myJsonStore, 
      structure: myStructure 
      onHeaderCellClick:getSortedTable 
     }; 

現在,這裏是我想用撥打另一個電話到服務器的getSortedTable功能 - 傳遞單元名稱,表名和排序順序(asc或desc)。

function getSortedTable(e) 
    { 
    var cellName = e.cell.name; 
      var tableName = ? 
      var sortOrder = ? 
      // getSortedTablefromServer(cellName, sortOrder, tablename) 
    } 

但我唯一能夠從'e'參數中獲得的thihng是單元格名稱,可以是表名稱。

  1. 我怎樣才能得到或保持一個天氣的軌道,這將是由用戶要求升序或降序。
  2. 此外 - 我將如何顯示列標題上的小箭頭以向用戶顯示數據處於降序還是升序?

任何幫助是高度讚賞!

感謝,

回答

0

你可能會更好過修改您的數據存儲來處理服務器端排序,而不是網格(例如附加排序標準作爲查詢參數由fetch(),而觸發XHR呼叫比排序結果集客戶端)。網格應該像客戶端排序一樣運行,因爲它只會反映數據存儲的排序順序。

dojo.data.api.Read關於fetch()

If a sort parameter is specified, this is a indication to the datastore to 
sort the items in some manner before returning the items. The array is an array of 
javascript objects that must conform to the following format to be applied to the 
fetching of items: 
    { 
     attribute: attribute || attribute-name-string, 
     descending: true|false; // Optional. Default is false. 
    } 
Note that when comparing attributes, if an item contains no value for the attribute 
(undefined), then it the default ascending sort logic should push it to the bottom 
of the list. In the descending order case, it such items should appear at the top of the list. 
+0

我爲這個遲到的答覆道歉。我仍然需要回到這個問題。到現在爲止,還有其他一些東西。我會嘗試執行抓取並找回我發現的內容...感謝您的回覆! – 2010-01-31 08:16:28

0

我想你可能會改變你的店。我正在使用jsonRestStore的網格來代替。因此,每次通過單擊列更改排序時,網格都會發起請求。

這裏是我的網

require([ 
    "dojox/grid/EnhancedGrid", 
    "dojox/data/JsonRestStore", 
    "dojox/grid/enhanced/plugins/NestedSorting", 
    "dojo/domReady!", 
    "dojox/grid/cells/dijit" 
], function(DataGrid, JsonRestStore) { 
    dataStore = new JsonRestStore({ 
     target: "/url_to_your_be" 
    }); 
    grid = new DataGrid({ 
     store: dataStore, 
     plugins: {"nestedSorting": true}, 
     query: "?something=1", 
     structure: [ 
      { 
       defaultCell: { editable: false}, 
       cells: [ 
        { name: "col 1", field: "col_1", width: "50px"}, 
        { name: "col 2", field: "col_2", width: "50px"} 
       ] 
      } 
     ], 
     selectionMode: "single", 
     sortFields: [{attribute: 'col_1', descending: false},{attribute: 'col_2', descending: false}] 
    }, "yourGridId"); 
    grid.startup(); 
}); 

sortFields是用於設置排序上你的第一個負載,如果你不需要它可以忽略不計。

每次你在頭點擊它發送類似

http//www.yourwebsite.com/url_to_your_be/?something=1&sort(+col_1,+col_2)

的請求,即使要更改查詢

var grid = dijitRegistry.byId('yourGridId'); 
grid.setQuery("?something=2"); 

請求將

`http//www.yourwebsite.com/url_to_your_be/?something=2&sort(+col_1,+col_2)` 

現在你可以在你的BE a中分割$ _GET數據數據範圍的報頭

[{"col_1": 1, "col_2": "something"},...] 

:ND做排序

我BE正在發送數據作爲JSON對象

Content-Range: items=0-10/100