SitePen / dgrid

A lightweight, mobile-ready, data-driven, modular grid widget designed for use with dstore
http://dgrid.io/
Other
628 stars 298 forks source link

(ColumnSet +) CompoundColumns_findSortArrowParent(field) fails to find parent out of the 1st column set #1474

Open claudeG opened 4 years ago

claudeG commented 4 years ago

Hello ! We worked with Dgrid-0.3 plus an integration layer for several years and I am currently preparing the upgrade to the lastest Dgrid.

I have the case of an OnDemandGrid that results from declare([MyOnDemanGrid, ColumnHider, ColumnResizer, CompoundColumns, ColumnSet, Keyboard, Editor, DijitRegistry], {...}) where MyOnDemanGrid results from declare([OnDemandGrid, Selector, MouseOverEvents, ProgressDialog], {...}).

This grid instance holds 2 sets of columns. In boths sets, columns may be sortable or not. When the header of a sortable column is clicked, the sort arrow must update. In our case, the retrieval of the sort arrow node relies on CompoundColumns_findSortArrowParent(field) because the "this._sortNode" is null.

The issue I encounter : When I click the header label from the second column set, such a node is not found. Debugging CompoundColumns_findSortArrowParent(field),

    _findSortArrowParent: function () {
        var parent = this.inherited(arguments),
            spacerRow = query('.dgrid-spacer-row', this.headerNode)[0],
            columnId,
            nodes;

        if (parent && spacerRow.contains(parent)) {
            columnId = parent.columnId;
            nodes = query('.dgrid-column-' + columnId, this.headerNode);
            return nodes[nodes.length - 1];
        }
    }

I noted that the node search is constrained by spacerRow.contains(parent) where spacerRow is the 1st '.dgrid-spacer-row' element. But our case fails because 'parent' belongs to the 2nd spacerRow. PROBLEM.

The way I solved this issue temporary:

lang.extend(CompoundColumns, {
    _findSortArrowParent: function(field) {
        // dgrid/CompoundColumns searches for 'parent' in the first '.dgrid-spacer-row' element only
        // while it exists as many '.dgrid-spacer-row' elements as compound column sets
        var parent = this.inherited("_findSortArrowParent", arguments); // Grid
        if (parent) {
            var allSpacerRows = query('.dgrid-spacer-row', this.headerNode);
            var someSpacerRowContainsParent = allSpacerRows.some(function(row) {
                return row.contains(parent);
            });
            if(someSpacerRowContainsParent) {
                var columnId = parent.columnId;
                var nodes = query('.dgrid-column-' + columnId, this.headerNode);
                return nodes[nodes.length - 1];                     
            }
        }
    }
});

One more issue (I did not try to correct it) : The presence of a given data column should not be required to be unique in a grid. Sorting any column instance should be reflected on the sort icon of each of its "clones".

Thanks for your attention.

Claude