rowGroup - Display multiple column values in Group Header.

rowGroup - Display multiple column values in Group Header.

DTDev77DTDev77 Posts: 4Questions: 2Answers: 0

Hello,
i got a datatable with rowGroup, using following code:

'rowGroup': {
                        startRender: function (rows,group ) {
                            return group;
                        },
                        dataSrc: [1],
                    },

This produces a Group like:

Name


Street | ID | Order
Street | ID | Order
Street | ID | Order
Street | ID | Order

And i want a group which looks like:

Name - Street - ID


Order
Order
Order
Order

How can i access the Data and how to modify the group header?

Best Regards,
DTDev

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,658Questions: 1Answers: 10,494 Site admin

    You'd hide the street and id columns using columns.visible and you'd use the rowGroup.startRender to build the string that you want to display in the grouping row. There is an example of that here.

    Allan

  • DTDev77DTDev77 Posts: 4Questions: 2Answers: 0

    Thank you,
    Columns Visibile seems to be clear, start Render too, but i can't figure out how to access the data, it must be something like:

    'rowGroup': {
                            startRender: function (rows,group ) {
                                return group + ' ' + data[1];
                            },
                            dataSrc: [1],
                        },
    
    
  • allanallan Posts: 63,658Questions: 1Answers: 10,494 Site admin
    Answer ✓

    rows.data() will give you the data for the rows in the group. So you could do rows.data().eq(0) to get the data for the first row in the group.

    Then it depends on your data is an array or an object - if you use columns.data then most likely it is object based and you'd do something like data.myProperty or if it is array based data[0].

    Allan

  • DTDev77DTDev77 Posts: 4Questions: 2Answers: 0

    That's was i needed,

    many thanks!

  • gordonc200gordonc200 Posts: 39Questions: 7Answers: 0
    edited May 2018

    I have a similar problem to the above. The data I'm trying to group comes from an array (the JSON the editor returns from the PHP script). The structure is below.

    The column data is from a linktable. The column (arbitrarystamps) can have multiple entries. In the case of the above there is only one column entry but it's generated from a select multiple field. The column could also be blank.

    If it helps the code to get the data to render in the column (which works) is

    {//column 17
                    "data": "arbitrarystamps",
                    "render": function ( data, type, full ) {
                        return $.map( data, function ( d, i ) {
                            return d.arbitrarystamp;
                        } ).join( ', ' );
                    }
                }
    

    Is this possible please?

This discussion has been closed.