Thursday 15 April 2010

jquery - Replace content in DataTables column based on word -



jquery - Replace content in DataTables column based on word -

how can replace value of cell in column in datatables, based on word in cell. example, if word "active", word in green. if word "inactive" in red. can highlight words within same column, not target column based on word or first letter.

datatables code:

$('#datatables-example').datatable( { "ajax": 'publishers.txt', "createdrow": function ( row, data, index ) { if ( data[3].replace(/[\a,]/, '')) { $('td', row).eq(3).addclass('highlight'); } } });

css:

td.highlight { font-weight: bold; color: blue; }

found solution in datatables reference docs:

"columndefs": [ { "targets": 3, "createdcell": function (td, celldata, rowdata, row, col) { if ( celldata == "active" ) { $(td).css('color', 'green') } if ( celldata == "inactive") { $(td).css('color', 'red') } } } ]

jquery css datatables

No comments:

Post a Comment