Looping through columns but getting the value of another

Looping through columns but getting the value of another

johnblythejohnblythe Posts: 92Questions: 21Answers: 2

Hey Alan,

I'm using the following code to loop through columns in order to create a 'header' row of sorts for items to be grouped on (I think you had posted this somewhere on the site and I snagged it, but I can't currently locate it)

api.column(10, {page:'current'} ).data().each( function ( group, i ) {
    var construct = api.row(i).data()[9];
    if ( last !== group ) {
        $(rows).eq( i ).before(
            '<tr class="construct-head"><td colspan="17" class="readonly">'+construct+'</td></tr>'
         );
    last = group;
    }
});

I'm using column 10 because it's what is unique amongst the data. Column 9 is what I actually need to show, however. The reason is that there 10 references a unique ID, but 9 references that IDs description. The problem in using 9 is that some items would be grouped that don't need to be because their other data points set them apart from one another while their descriptions do not.

How can I access the row's data to grab data()[9]? When I use dt.rows(i).data() it's grabbing another one, seemingly, than the one the current column() is looping through because the group value and data()[9] are not the same.

Thanks for any assistance

Answers

  • johnblythejohnblythe Posts: 92Questions: 21Answers: 2
    edited November 2015

    what i've done for now is simply combine those two fields (the non-unique description and the unique id) for the Datatable to load and group correctly based on unique values, but then when I print out the value I simply use split("-")[0]" to get the description in place visually. so, i've got it fixed for now as far as use case is concerned. i'd still love to know the best way to access the row's data in the DT api() in this sort of context.

    thanks!

This discussion has been closed.