Highlight duplicate values in columns
Highlight duplicate values in columns
I apologize if this is too simple of a question to ask about. I've just started using DataTables/Editor. I'm trying to highlight duplicate values in columns 1 and 2. I have already been able to highlight cells containing certain letters using cellData, but I am having a hard time with the duplicates. I have looked at some of the rowCallback examples and have not been able to get them to work. Can I edit/add on to the columnDefs to achieve this? JS attached below. Thank you in advance for any help you can give.
$('#example').DataTable( {
dom: "Bfrtip",
ajax: "../ajax/production.php",
paging: false,
scrollY: "500px",
scrollCollapse: true,
autoFill: {
editor: editor
},
columns: [
{
data: null,
defaultContent: '',
className: 'select-checkbox',
orderable: false
},
{ data: "field1" },
{ data: "field2" },
{ data: "field3" },
{ data: "field4" },
{ data: "field5" },
{ data: "field6" },
{ data: "field7" },
{ data: "field8" }
],
select: {
style: 'os',
selector: 'td:first-child'
},
buttons: [
{ extend: "create", editor: editor },
{ extend: "edit", editor: editor },
{ extend: "remove", editor: editor }
],
columnDefs: [ {
targets: [6], visible: false},
{
targets: [1, 2],
createdCell: function (td, cellData, rowData, row, col) {
if ( cellData.indexOf('CT') > -1
|| cellData.indexOf('Ct') > -1
|| cellData.indexOf('ct') > -1
|| cellData.indexOf('AE') > -1
|| cellData.indexOf('Ae') > -1
|| cellData.indexOf('ae') > -1
|| cellData.indexOf('RTU') > -1
|| cellData.indexOf('Rtu') > -1
|| cellData.indexOf('rtu') > -1
)
{
$(td).css('background-color', 'Orange'),
$(td).css('color', 'White')
}
}
}
]
});
This question has an accepted answers - jump to answer
Answers
Hi @opei ,
Yep, you could do something like this in
rowCallback
. You're using objects (my example is using array), so just changedata[1]
to bedata.field1
,Cheers,
Colin
Worked perfect! Thank you @colin