change columndDefs after document is ready possible ?

change columndDefs after document is ready possible ?

fahrstuhl65fahrstuhl65 Posts: 13Questions: 0Answers: 0

Hi,

i set my table columnDefs after document ready like this example and this still works as expected (i use 12,23 as decimal seperator, so i have to change this twice):

        "columnDefs": [{
            "targets": [3, 6, 7, 8, 9, 10, 11],
            "createdCell": function (td, cellData, rowData, row, col) {

                //Remove the formatting to get integer data for summation
                cellData = cellData.replace(',', '.');
                
                if (cellData < 0) {
                    
                    $(td).css('color', 'red')
                    $(td).text(cellData.replace('.', ',') + ' \u20AC');
                }
                if (cellData >= 0) {
                    $(td).css('color', 'green')
                    $(td).text(cellData.replace('.', ',') + ' \u20AC');
                }
            }
        }],

Now I use a Select which filter my table with columns.search.

Depending on the selected value of the Select i need the possibility to change also the columnDefs
to append instead of the € sign the $ sign in the cells.

Best would be to fire an event from the Select

$('#Select').on('change', function () {....}

How can i achieve this ? Or can anyone show a way to change this after document is ready ?

Thanks a lot

fahri

Replies

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

    Instead of using columns.createdCell (which is only called when the cell is created), move the logic into rowCallback as this is called on every draw. That should do the trick,

    Colin

  • fahrstuhl65fahrstuhl65 Posts: 13Questions: 0Answers: 0

    Hi Collin,

    thanks a lot for your reply. It helped me an i could resolve this now !

    With best regards
    fahri

This discussion has been closed.