How to highlight row with duplicate column data

How to highlight row with duplicate column data

marin63marin63 Posts: 2Questions: 1Answers: 0
edited June 2018 in Free community support

Please all i need assistance on how to highlight rows with duplicate column data (Note i am considering the barcode column)

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @marin63 ,

    You can use rowCallback to do this - see this example here,

    Cheers,

    Colin

  • marin63marin63 Posts: 2Questions: 1Answers: 0
    edited June 2018

    Thanks @colin ,
    I have been able to achieved it with this code:

                            let table = $.fn.dataTable.tables({ api: true })
                            let barcodes = table.columns( 5 ).data()[0]
                            let num = 0
    
                            table.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
                                var code = this.data()[5]
    
                                barcodes.forEach( function (barcode) {
                                    if ( barcode === code )
                                        num++
                                } )
    
                                if ( num > 1 )
                                    $(this.node()).addClass('duplicate')
    
                                num = 0
                            } )
    
This discussion has been closed.