您好,根据您的描述,我给您的方案是:
1、首先,当数据在页面端加载时,默认是会以dataSource数据源的排列顺序来排序的;
2、如果需要在加载时就自动排序,可以通过theGrid.rows.sort()来实现。参考以下代码:
- import 'bootstrap.css';
- import '@grapecity/wijmo.styles/wijmo.css';
- import * as wjGrid from '@grapecity/wijmo.grid';
- //
- document.readyState === 'complete' ? init() : window.onload = init;
- //
- function init() {
- //
- // create some random data
- var countries = 'US,Germany,UK,Japan,Sweden,Norway,Denmark'.split(','), data = [];
- for (var i = 0; i < countries.length; i++) {
- data.push({
- id: i,
- country: countries[i],
- active: i % 5 != 0,
- downloads: Math.round(Math.random() * 200000),
- sales: Math.random() * 100000,
- expenses: Math.random() * 50000
- });
- }
- //
- // create the grid with on-demand sorting
- var view;
- var theGrid = new wjGrid.FlexGrid('#theGrid', {
- itemsSourceChanged: function (s, e) {
- view = s.collectionView;
- view.canSort = false; // prevent sorting
- },
- sortedColumn: function (s, e) {
- view.canSort = false; // prevent sorting
- view.sourceCollection = view.items; // copy sorted values
- },
- alternatingRowStep: 0,
- itemsSource: data
- });
- //
- // allow sorting by mouse click
- theGrid.hostElement.addEventListener('mousedown', function (e) {
- if (theGrid.hitTest(e).panel == theGrid.columnHeaders) {
- view.canSort = true;
- }
- }, true);
- theGrid.rows.sort(function(a, b){
- return -1;
- });
- }
复制代码
这段代码可以完全拷贝到这个示例上运行:
https://demo.grapecity.com.cn/wi ... ng/On-demand/purejs
参考API:
https://demo.grapecity.com.cn/wi ... ollection.html#sort
|