How to not use "no group" in the extension rowGroup?

How to not use "no group" in the extension rowGroup?

amitywebamityweb Posts: 5Questions: 3Answers: 0

Some of my rows have groupings (in my case they are like child entries of the parent), but some dont. I would like those that do have row groupings to be grouped, but those that dont, dont. Just have them as normal rows ungrouped, and be ordered within the same sorting as the groups. So I would only see the groupings for those with child entries.

So it would be like this:

Element 1
- Element 1 Child 1
- Element 1 Child 2
- Element 1 Child 3
Element 2
Element 3
- Element 3 Child 1
- Element 3 Child 2

Thanks

Answers

  • colincolin Posts: 6,896Questions: 0Answers: 1,179

    Hi @amityweb ,

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • rossbobrossbob Posts: 21Questions: 2Answers: 0
    edited December 4

    I know this is from last year, but I have the same issue with rowGroup. not sure if youve managed to get what your suggesting working with rowGroup. I have resolved it with the following code I found somewhere;

        let groupColumn = 3;
        let table = $('#table').DataTable({            
        "drawCallback": function ( settings ) {
                let api = this.api();
                let rows = api.rows( {page:'current'} ).nodes();
                let last=null;
    
                api.column(groupColumn, {page:'current'} ).data().each( function ( group, i ) {
                    if ( last !== group ) {
                        $(rows).eq( i ).before(
                            '<tr class="group text-center greyRow"><td colspan="4"><b>'+group+'</b></td></tr>'
                        );
    
                        last = group;
                    }
                } );
            },
    

    To make sure we are talking about the same thing, you mean you want anything were group is empty or null to not be grouped under a heading? rowGroup doesnt seem to support this whereas the above code does. My preference would be to use rowGroup.

  • rossbobrossbob Posts: 21Questions: 2Answers: 0
    edited December 5

    Found this in documentation;

    **The text that will be shown in the grouping row for the data.

    If null is given as the value, no grouping row will be shown (since 1.0.3).**

    This doesnt work for me. I have version 1.1.0 of rowGroup. Im getting js error, that cant be found, if the value is set to null. Guess i must be doing something wrong. Here is my code when using rowGroup;

                rowGroup: {
                    className: 'vendor_details',
                    dataSrc: function(row) {
                        return row.pg.segment_title;
                    },
                    startRender: function ( rows, group ) {
                        return group +' ('+rows.count()+' rows)';
                    }
                },
    

    The only way I can get the above code to work, when the segment_title is null, is to do the following;

    return row.pg.segment_title === null ? "Not Categorised": row.pg.segment_title;

  • rossbobrossbob Posts: 21Questions: 2Answers: 0

    This is the error message I get when the value returned in dataSrc is null

    dataTables.rowGroup.min.js:21 Uncaught ReferenceError: that is not defined
    at h._group (dataTables.rowGroup.min.js:21)
    at h._draw (dataTables.rowGroup.min.js:20)
    at HTMLTableElement.<anonymous> (dataTables.rowGroup.min.js:20)
    at HTMLTableElement.dispatch (jquery.min.js:2)
    at HTMLTableElement.y.handle (jquery.min.js:2)
    at Object.trigger (jquery.min.js:2)
    at HTMLTableElement.<anonymous> (jquery.min.js:2)
    at Function.each (jquery.min.js:2)
    at w.fn.init.each (jquery.min.js:2)
    at w.fn.init.trigger (jquery.min.js:2)

  • kthorngrenkthorngren Posts: 7,010Questions: 22Answers: 1,529

    it seems to work here with null data.
    http://live.datatables.net/zoquhemu/1/edit

    You can try with dataSrc as a function or directly assigning the column. It produces the same result.

    Maybe you can update the test case to replicate your issue. Or provide a link to your page.

    Kevin

Sign In or Register to comment.