RowGroup Questions

RowGroup Questions

DalderDalder Posts: 30Questions: 12Answers: 1

Hi folks,

I've got a couple of things that are outside of the normal scope of the RowGroup extension and was wondering if anyone could offer up a solution?

Here is my example setup

My first question is to do with the grouping itself.

If you look at the HTML of my table you'll see the last column, Active, is set to 0.

If you change that to a 1 in any of the rows, you'll see it jump to the top.

This is what I want, but when a row jumps to the top I'd like it to sit in a separate "Active Operations" group.

I thought I could achieve this by overloading the default startRender property with this:

"startRender": function ( rows, group ) {
    live_jobs = rows.data().pluck(17).reduce(function(a,b){return parseInt(a) + parseInt($(b).text())}, 0);
    if (!live_jobs) {
        return '<b>' + group + '</b>';
    } else {
        return '<b><div>Active Jobs</div></b>';
    }
}

Whilst this works if I choose a row outside of the first group, it falls apart when i chose a row in the first group as it renames the whole group rather than creating a new one.

How can I get around this?

My second question is to do with summing of HTML5 data-* attributes.

If you look at HTML for columns 5 through 14, you will see they have data attributes which are floats. These are hours as decimal units. What I need to do is add all of these together for a group and show the total in a row after the group. I understand that I will use endRender to display the row, but I'm struggling to find an efficient way of getting these values from the rows in a group, can anyone help?

I feel like I've possibly been a bit vague in areas, so please let me know if you require clarification on anything I've said.

Many thanks,

Dan

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,471Questions: 1Answers: 10,467 Site admin
    Answer ✓

    Hi Dan,

    It sounds like you really want two dimensions to the row grouping - one for the date and one for the status. That I'm afraid is not something that RowGroup is currently able to do. You'd need the grouping data point to contain all of the information that you want to be able to group on.

    The rows parameter which is passed in to rowGroup.endRender will help for the second point:

    $('[data-lftime]', rows.nodes()).each( function () {
      var attrVal = this.getAttribute('data-lftime');
      ...
    } );
    

    There are probably other ways to do it with map or reduce, but that's the basic idea.

    Allan

This discussion has been closed.