rowGroup only Append count to Top rowgroup

rowGroup only Append count to Top rowgroup

zgoforthzgoforth Posts: 493Questions: 98Answers: 2
edited August 2021 in DataTables 1.10

Link to test case: https://jsfiddle.net/BeerusDev/5nLg4bt0/85/

Hello,

I am curious how I can replace the count character added to the 2nd row group (but remain in the first).

The data that I am applying to the second sub rowGroup looks like (1) High, (2) Normal, (3) Low. And with the count next to the data it is kind of an eye sore and could be confusing to some as it will look like:

(1) High (1) //desired result => (1) High

(2) Normal (1) //desired result => (2) Normal

The class that is applied to these sub rowGroups is collapsed dtrg-group dtrg-start dtrg-level-1 if that matters

Answers

  • kthorngrenkthorngren Posts: 21,324Questions: 26Answers: 4,949

    The rowGroup.startRender docs describe the parameters with one of them being level. This is the group level. You can use this to customize the string that is returned for each group level at the end of the function.

    Kevin

  • zgoforthzgoforth Posts: 493Questions: 98Answers: 2

    Working example: https://jsfiddle.net/BeerusDev/5nLg4bt0/102/

    I checked out the docs and wasn't able to find how to target the levels. Aside from only appending the count to the 0 level row, I want to also only append the priorityClass colors I defined in the rows.every() to to the subrows (level 1). Is that achievable with the rowgroup.startRender as well?

  • kthorngrenkthorngren Posts: 21,324Questions: 26Answers: 4,949

    The first part of your rowGroup.startRender function uses the level to handle collapsing the groups at both levels. Do something similar with if statements to process the data appropriately for each level.

    Kevin

  • zgoforthzgoforth Posts: 493Questions: 98Answers: 2

    Got it:

                        if(level === 0){
                        return $('<tr/>')
                            .append('<td colspan="8" style="text-align: left;">' + group + ' (' + rows.count() + ')</td>')
                            .attr('data-name', all)
                            .toggleClass('collapsed', collapsed);
                        } else if (level === 1) {
                        return $('<tr/>').addClass(priorityClass)
                            .append('<td colspan="8" style="text-align: left;">' + group + '</td>')
                            .attr('data-name', all)
                            .toggleClass('collapsed', collapsed);
                        }
    
Sign In or Register to comment.