矩列中的触发函数在GridX中排序

时间:2018-08-05 06:20:07

标签: javascript dojo dojo.gridx gridx

我在Gridx中使用SingleSort模块。我找不到(我已经检查过SingleSort文档,却一无所获)对排序事件做出反应的方法。我需要有关对(和如何)列进行排序的信息。我知道如何获取有关排序的信息(getSortData方法),但我不知道make在做出即时排序时如何做出反应。我无法使用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");
        })
    },
});
});

1 个答案:

答案 0 :(得分:0)

您需要使用像这样的gridx SingleSort模块排序方法

 this._grid.connect( this._grid.Sort, 'sort', function(colId, isDescending, skipUpdateBody){
        alert(colId+" "+isDescending+" "+skipUpdateBody);
    });

这将在对网格列进行排序时触发事件。希望这会有所帮助。