Help with colum render please

Help with colum render please

NefariousNefarious Posts: 3Questions: 2Answers: 0

I am using datatables and would like to over-ride the contents of a cell depending on the value it contains. I am using '1' to flag true in the underlying database and '0' for false. I am attempting to use the Columndefs render function to do this.

Here is my code..

    xample_table = $('#treatment_list').DataTable(
        {
        select: true,
        destroy: true,
         "order": [ 0, 'desc' ],
            data:json,
            columns : [
                {'data':'treatment_name'},
                {'data':'description'},
                 {'data':'measured_in'},
                {'data':'exclusive'}
                ],
           "columnDefs": [
                {      
                  "targets":3,
                  "data" : "exclusive",
                    "render": function ( data, type, row ) {
                        if (type === 'display'){
                   
                            if (row.exclusive == '0')
                                {
                                 return 'No';
                                }
                            else
                             return 'Yes';
                        }
                        
                        
                    }
                }
            ]
    
    }
    
    );

The problem is I get an erro message from datatables that reads..

DataTables warning: table id=treatment_list - Requested unknown parameter 'exclusive' for row 0, column 3....

Apart from the error message, it is in fact working. If anyone can help, I would be very grateful.

Many thanks.. Dave.

Answers

  • kthorngrenkthorngren Posts: 20,145Questions: 26Answers: 4,736

    With columns.render you always need to return something. If type is unequal to display you aren't returning anything. Add return data; to line 27 after the if statement.

    Kevin

  • colincolin Posts: 15,118Questions: 1Answers: 2,583

    @starcmr We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • colincolin Posts: 15,118Questions: 1Answers: 2,583

    @starcmr - I just noticed you spammed here too - please note you'll be banned if you do that again...

    Colin

Sign In or Register to comment.