0

我将 SingleSort 模块与 Gridx 一起使用。我找不到(我已经检查了 SingleSort 文档但一无所获)对排序事件做出反应的方法。我需要有关对哪个(以及如何)列进行排序的信息。我知道如何获取有关排序的信息(getSortData 方法),但我不知道如何在排序时做出反应。我无法制作 onRender-event 函数,因为在排序后我会将该信息发送到 webapi 获取新数据并再次渲染 Grid,因此将再次触发事件。

define([
"dojo/Evented",
"dojo/_base/declare",
"dojo/store/Memory",
"gridx/core/model/cache/Sync",
"gridx/Grid",
"gridx/modules/ColumnResizer",
'gridx/modules/Focus',
'gridx/modules/RowHeader',
'gridx/modules/select/Row',
'gridx/modules/select/Column',
'gridx/modules/select/Cell',
"gridx/modules/SingleSort"
], function (Evented, declare, Memory, Cache, Grid, ColumnResizer, Focus, RowHeader, SelectRow, SelectColumn, SelectCell, Sort) {
return declare([Evented], {

    _counter: 1,

    _topOffset: 100,

    constructor: function () {
    },

    initialize: function () {
        this._initGrid();
        this._resizeGridContainer();
    },
    clear: function () {
        var store = new Memory({ data: [] });
        this._grid.setStore(store);

        this._counter = 1;
    },
    _initGrid: function () {
        var _this = this;

        var store = new Memory({
            data: []
        });
        var structure = [
            {
                id: 'operationType', field: 'operationType', name: dojo.byId(this._operationTypeId).value                   
            },
            {
                id: 'transportationType', field: 'transportationType', name: dojo.byId(this._transportationUnitTypeId).value
            },
            {
                id: 'transportationTypeLength', field: 'transportationTypeLength', name: dojo.byId(this._transportationLengthId).value
            }              
        ]

        this._grid = Grid({
            id: this._gridId,
            cacheClass: Cache,
            store: store,
            structure: structure,
            modules: [
                ColumnResizer,
                Sort
            ],
            selectRowTriggerOnCell: true
        });
        this._grid.placeAt(this._gridPlaceholderId);
        this._grid.startup();
    },

    _resizeGridContainer: function () {
        var _this = this;
        var container = dojo.byId(this._gridContainerId);
        var height = container.parentElement.clientHeight - this._topOffset;

        require(["dojo/dom-style"], function (domStyle) {
            domStyle.set(_this._gridContainerId, "height", height + "px");
        })
    },
});
});
4

1 回答 1