Conditionally formatting a RowGroup header based on values in the group

Conditionally formatting a RowGroup header based on values in the group

htwyfordhtwyford Posts: 23Questions: 9Answers: 1

Each row of my data has a boolean condition passed to it in JSON. I am using RowGroup to group rows, and would like to apply a class to the <tr> containing the group header if the boolean is true for any of the rows in the group. I can't seem to get this to work using the rowCallback attribute. My code:

rowCallback: function (row, data, index) {
    if (data.Condition === true) {
        var groupRow = $(row).prev('.group')
        groupRow.addClass("MyClass");
    }
}

I'm not sure where I've gone wrong here. The row passed to the function in rowCallback is an instance of node(). JQuery docs seem to suggest I can access its siblings with prev(), and I can get the first sibling above it with the .group class by calling .prev('.group').

Is it that the group header <tr>s don't have the '.group' applied to them yet?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,716Questions: 1Answers: 10,108 Site admin
    Answer ✓

    The rowCallback option is not the way to do this. The grouping rows don't exist in the DOM when rowCallback is called, which is why it won't work.

    Instead, I would suggest you use rowGroup.startRender to define the grouping row. You can use the first parameter that is passed in to check the data for the group to see if it contains a row matching your condition.

    Allan

This discussion has been closed.