addclass to cell

addclass to cell

MadMax76MadMax76 Posts: 149Questions: 33Answers: 1

Hi,

I am having a column where I add a icon for deleting or canceling depedning on the status of the row-item. I also need to add a class, this is what does not work.

Here is my code for this column:

 {
                    data: null,
                    render: function (data) {
                        if(data.mytab.Re_Status < 50){
                            return '<i class="fa fa-trash btn-kl" style="color: #90a51d" title="Element löschen" />';
                        } else if (data.mytab.Re_Status < 90 && data.mytab.Re_Art_Text != 'Storno') {
                            return '<i class="fa fa-times btn-kl" style="color: red" title="Element stornieren" />';
                        } else {
                            return ' ';
                        }
                    },
                    createdCell: function (td, cellData, rowData, row, col) {
                        if ( cellData < 50 ) { $(td).addClass('ausgreloeschen dt-center editor-edit');
                        } else if (cellData < 90) { $(td).addClass('ausgrestorno dt-center editor-edit');
                        }
                    },
                    orderable: false,
                    cursor: 'pointer'
                }, 

If i set
data: mytab.Re_Status
the whole datatable does not work anymore (it is not rendered, although data is loaded).

Any idea how to solve this?

Thanks
Max

Answers

  • colincolin Posts: 15,161Questions: 1Answers: 2,588

    Have a look at createRow, there's an example there similar to what you're after. There it's adding a class to the row, but it just needs a tighter selector to add it onto the cell.

    This example is using columns.render, so may also be handy.

    Colin

  • MadMax76MadMax76 Posts: 149Questions: 33Answers: 1

    thanks, solved it by optiming the render-part:

    {
                        data: "mytab.Re_Status",
                        render: function (data, type, row, meta ) {
                            if(data < 50){
                                return '<i class="ausgreloeschen fa fa-trash btn-kl" style="color: #90a51d" title="Element löschen" />';
                            } else if (data < 90 && row.mytab.Re_Art_Text != 'Storno') {
                                return '<i class="ausgrestorno fa fa-times btn-kl" style="color: red" title="Element stornieren" />';
                            } else {
                                return ' ';
                            }
                        },
                        createdCell: function (td, cellData, rowData, row, col) {
                            if ( cellData < 50 ) { $(td).addClass('ausgreloeschen dt-center editor-edit');
                            } else if (cellData < 90) { $(td).addClass('ausgrestorno dt-center editor-edit');
                            }
                        },
                        orderable: false,
                        cursor: 'pointer'
                    }
    
Sign In or Register to comment.