Ext.data.Store使用樣本(二)

來源:互聯網
上載者:User
二、對資料進行排序

  Ext.data.Store提供了一系列屬性和函數,利用它們對資料進行排序操作。

  可以在建立Ext.data.Store時使用sortInfo參數指定排序的欄位和排序方式,如下面的代碼所示。

  var store = new Ext.data.Store({

  proxy: new Ext.data.MemoryProxy(data),

  reader: new Ext.data.ArrayReader({}, PersonRecord),

  sortInfo: {field: 'name', direction: 'DESC'}

  });

  這樣,在store載入資料之後,就會自動根據name欄位進行降序排列。對store使用store.setDefaultSort('name','DESC');也會達到同樣效果。

  也可以在任何時候調用sort()函數,比如store.sort('name', 'DESC');,對store中的資料進行排序。

  如果我們希望獲得store的排序資訊,可以調用getSortState()函數,返回的是類似{field: "name", direction: " DESC"}的JSON對象。

  與排序相關的參數還有remoteSort,這個參數是用來實現後台排序功能的。當設定為remoteSort:true時,store會在向後台請求資料時自動加入sort和dir兩個參數,分別對應排序的欄位和排序的方式,由後台擷取並處理這兩個參數,在後台對所需資料進行排序操作。remoteSort:true也會導致每次執行sort()時都要去後台重新載入資料,而不能只對本機資料進行排序。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.