Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude certain group-rows from grid #40

Open
Excelautomation opened this issue Jul 18, 2016 · 4 comments
Open

Exclude certain group-rows from grid #40

Excelautomation opened this issue Jul 18, 2016 · 4 comments

Comments

@Excelautomation
Copy link

Excelautomation commented Jul 18, 2016

Hi, thank you for supporting on this grid - hope you can help me out with the following:

I've been struggling with appropriate way to hide/exclude certain group-headers from being included in the grid. As the image below pretty obviously display, I'd like the headers with: "HIDE THIS" to be excluded from the grid, as this group will only contain 1 item. Nevertheless, I really like the 2. part ("2. variations") of the level 1-grouping.

I'm using 2 levels grouping in my grid; where the first group is grouping by title (String), and the second level is grouping by a child-attribute (Boolean).

Image:
http://prntscr.com/bujgq9

Group-code:

` function groupByParentID() {

    dataView.setGrouping([{
        getter: "parent_id",
        formatter: function ( g ) {
            return '<strong>' + g.rows[0].title + '</strong><span class="grey-field"> (ID: ' + g.value + ')</span>';
        },
        aggregateCollapsed: false,
        lazyTotalsCalculation: true
    }, {
        getter: "child",
        formatter: function ( g ) {
            if ( g.rows[0].title ) {
                return 'HIDE THIS';
            } else {
                return "<span class='grey-field'>" + g.count + " variations</span>"
            }
        },
        aggregateCollapsed: false,
        lazyTotalsCalculation: true
    }]);
}`
@6pac
Copy link
Owner

6pac commented Jul 21, 2016

Sorry I can't do this right away - perhaps in a few days - but I think where you'd want to start is the flattenGroupedRows function in slick.dataview.js. You should be able to do your logic there.
Using a formatter can make the row blank, but not remove it completely, whereas that function can.

@Excelautomation
Copy link
Author

Hi 6pac, thanks for pointing out the flattenGroupedRows.

I managed to implement this; it's kinda primitiv but it works.

The formatter returns "HIDE THIS", assigned as the rows title. I implemented the logic within the groups-iteration, where every rows is checked for this specific title. flattenGroupedRows is changed to:

  function flattenGroupedRows( groups, level ) {
        level = level || 0;
        var gi = groupingInfos[ level ];
        var groupedRows = [], rows, gl = 0, g;
        for ( var i = 0, l = groups.length; i < l; i++ ) {
            g = groups[ i ];
            groupedRows[ gl++ ] = g;

            if ( !g.collapsed ) {
                rows = g.groups ? flattenGroupedRows( g.groups, level + 1 ) : g.rows;
                for ( var j = 0, jj = rows.length; j < jj; j++ ) {
                    if ( rows[ j ].title != "HIDE THIS" ) {
                        groupedRows[ gl++ ] = rows[ j ];
                    }
                }
            }

            if ( g.totals && gi.displayTotalsRow && (!g.collapsed || gi.aggregateCollapsed) ) {
                groupedRows[ gl++ ] = g.totals;
            }
        }

        return groupedRows;

    }

@6pac
Copy link
Owner

6pac commented Aug 2, 2016

thanks for posting code!
it's a good use-case. i think i'll incorporate it into the grouping code sometime.
it could automatically do a COUNT of the group and hide if only one member.

@Excelautomation
Copy link
Author

Np!

Yes that would properly be the best solution.

Nevertheless, it's much better now :-) http://prntscr.com/c0jxbq

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants