moses toh
moses toh

Reputation: 13162

Insert color for each Row Grouping jQuery DataTables

I use API methods to perform row grouping

My code is like this : http://jsfiddle.net/oscar11/5jccbzdy/2/

// DataTable
    var table = $('#example').DataTable({
        "order": [[0, 'asc']],
        "drawCallback": function (settings){
            var api = this.api();

            // Zero-based index of the column containing names
            var col_name = 0;

            // If ordered by column containing names
            if (api.order()[0][0] === col_name) {
                var rows = api.rows({ page: 'current' }).nodes();
                var group_last = null;

                api.column(col_name, { page: 'current' }).data().each(function (name, index){
                    var group = name;

                    if (group_last !== group) {
                        $(rows).eq(index).before(
                            '<tr class="group"><td colspan="5">' + group + '</td></tr>'
                        );

                        group_last = group;
                    }
                });
            }
        }
    });

I want insert color for each row grouping by "css" column (You can see in http://jsfiddle.net/oscar11/5jccbzdy/2/. Column 5th). So, giving color to row grouping by css column. Thank you.

Upvotes: 0

Views: 1679

Answers (2)

Yasemin &#231;idem
Yasemin &#231;idem

Reputation: 623

if you want to all of column is colored ,this process is done in drawcallback function .The corrected version of the code is following. http://jsfiddle.net/5jccbzdy/8/

Upvotes: 0

Yasemin &#231;idem
Yasemin &#231;idem

Reputation: 623

insert following code inside DataTable function

"createdRow": function ( row, data, index ) {
                $('td', row).eq(4).addClass('highlight');
            }

http://jsfiddle.net/5jccbzdy/6/

Upvotes: 1

Related Questions