How to build a string using startRender and column data

How to build a string using startRender and column data

JalapenoJackJalapenoJack Posts: 2Questions: 1Answers: 0
edited November 2020 in Free community support

Hello,

I am using the rowGroup extension to group my data by my first column 'region'. My goal is to get the 'description' column data on the same line, so the group row will display as 'Region - Description'. I am essentially trying to create a string using the group name and an additional columns data.

I found this post but could not make much sense of the answer. Can anyone help me point me in the right direction?

This is the JS I am using-

$('#daytuh').DataTable({
'rowGroup': {
                        startRender: function (rows,group ) {
                            return group + ' - ' + 'Description here';
                        },
                        dataSrc: [0],
                    },
    columnDefs: [{
        targets: [0, 3],
        visible: false,
    }, ],
    paging: false
});

And I have set up this fiddle to assist

I have also tried using the rowGroup multiple data source method but in this case I would prefer for these to appear on the same row which is why I am trying this out.

Thanks so much!!

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,302Questions: 26Answers: 4,769
    Answer ✓

    Using the rows.data().eq(0) statement that Allan mentions will get the first row of data in the RowGroup. Then use that to set the description. For example:
    https://jsfiddle.net/aoLg1mx9/

    Kevin

  • JalapenoJackJalapenoJack Posts: 2Questions: 1Answers: 0

    Thank you! I can see where I was going wrong with my attempts now

This discussion has been closed.