jeudi 28 juillet 2016

How to change the background color of a coloumn in a jQuery DataTable?

Im new to jQuery and JavaScript, I want to change the background color of a specific column if the if statement is true.

$('#myTable').DataTable({
    "ajax": {
        "url": "/project/loadClientData",
        "type": "GET",
        "datatype": "json"
    },
    "columns" : 
    [
        { "data": "name", "autoWidth": true, "bSortable": true},
        {
            "data": "active", "autoWidth": true, "bSortable": true, "mRender": function (data, type, full, meta)
            {
                if (full.active == true) {
                    // i wanna make this cell background green.
                    return 'Ja';
                }   
                else {
                    return 'Nej';
                }
            }
        }
    ]
});

Aucun commentaire:

Enregistrer un commentaire