Restoring column order regarding rowgrouping.

Restoring column order regarding rowgrouping.

khaoskhaos Posts: 47Questions: 11Answers: 0

My test link will not load the ajax txt for whatever reason. https://jsfiddle.net/Cyberjetx/6as7o4gb/1/

The issue is after a reloading how can I set the group column. Currently we are using ordinals as in the main row group example. Is there a way to use a class or other more data driven method.

I tried the following:

function GetGroupOrdinal() {
    let retVal = 0;
    let elem = $('#CASREPTbl th');
    //console.log('Length : ' + elem.length);
    elem.each(function () {
        if ($(this).hasClass('grpBy')) {
            retVal = elem.index(this);
            console.log("GetGroupOrdinal: ", retVal);
        }
    });
    return retVal;
}

with the following:

...
                rowGroup: {
                dataSrc: (GetGroupOrdinal()),
                startRender: function (rows, group) {
                    var collapsed = !!collapsedGroups[group];

                    rows.nodes().each(function (r) {
                        r.style.display = collapsed ? 'none' : '';
                    });

                    // Add category name to the <tr>. NOTE: Hardcoded colspan
                    return $('<tr/>')
                        .append('<td colspan="99" class="RowGroupText">CASREP ' + group + ' (' + rows.count() + ')</td>')
                        .attr('data-name', group)
                        .toggleClass('collapsed', collapsed);
                }
            },
...

this works until the column reorder changes the group ordinal. I really am sorry I cant get the test link up and going. I hope you can see my issue.

Answers

  • khaoskhaos Posts: 47Questions: 11Answers: 0

    I wish I could edit this question. I was overthinking the base example. Still have the issue, however, I am ale to show the problem.

    https://jsfiddle.net/Cyberjetx/6as7o4gb/2/

    If you run the script you will see the desired result. Ig you change the ordinal of the "Office" column you no longer have your row grouping after running the script again.

    Datatables v1.12.1

  • kthorngrenkthorngren Posts: 21,261Questions: 26Answers: 4,934

    you change the ordinal of the "Office" column you no longer have your row grouping after running the script again.

    Are you referring to using colReorder? If so you can use the colReorder.transpose() to get the original order. Something like this maybe?
    https://jsfiddle.net/Lwva62d5/

    Kevin

  • khaoskhaos Posts: 47Questions: 11Answers: 0

    I wanted to leave the users new column order but have the rowgroup still on office. And consequently the order/fixed order. But one thing at a time I thought.

    Thanks so much for your time on this.

  • kthorngrenkthorngren Posts: 21,261Questions: 26Answers: 4,934

    I suspect order and orderFixed use the original order not the reordered index. I could be wrong. Please provide the steps to recreate the issue you are trying to solve.

    Kevin

Sign In or Register to comment.