Quantcast
Channel: DataTables 1.10 — DataTables forums
Viewing all articles
Browse latest Browse all 2364

Setting a column classname based on value of other column

$
0
0

Hi
I need to do as per above. Can I return and set a different classname based on the value inside one of a DT's columns?
How can this be achieved? Is using the column render method best or can it be best done by iterating all rows via DT's preinit event and how is the column's classname set then?

Here's what I have:

                { data: null,
                    defaultContent: '',
                    orderable: false,
                    render: function ( data, type, row ) {

                        if (IsTransTypeInvoiceLike(data.TransType) == true)
                        {
                            //return and set classname, but how?
                        }
                    },
                    className: 'details-control'
                },

or,

        var table = $('#tblDataTable1').DataTable();
        $('#tblDataTable1')
            .on( 'init.dt', function () {
                table.rows().eq(0).each( function ( index ) {
                    var row = table.row( index );
                    var data = row.data();
                    if (IsTransTypeInvoiceLike(data.TransType) == true)
                    {
                            //return and set classname, but how?
                    }                        
                } );
        }).dataTable();

I'm setting a different classname for the 1st column in this example: https://datatables.net/blog/2019-01-11

Many thanks.


Viewing all articles
Browse latest Browse all 2364

Trending Articles