shaik shaik - 1 year ago 112
Javascript Question

Apply className In datatables html equations

Hi I have a fn created row in my datatables with if condition if i gave a classname in column its working fine but when I try to give that class name in if condition datatable is not displaying could any one tell me to how to apply className in created rows. this is my code

var due_amount=aData['name'];
if(aData['due'] != "" && aData['id'] == aData['base_id'] && aData['status'] != "Active" )
due = '<span class="label label-red">'+aData['name']+'</span>';

Answer Source

Add a couple more parenthesis.

if( (aData['due'] != "")  && (aData['id'] == aData['base_id']) && (aData['status'] != "Active") )

What I often do to make a complex condition more readeable is this:

if( (aData['due'] != "")  && 
    (aData['id'] == aData['base_id']) && 
    (aData['status'] != "Active")

On multiple lines, missing characters or logic mistakes are easier to find.

Bonus question in comment:

If you split your things on multiple lines, it easier:

    "title": "S. No.",
    "orderable": false,
    },              // Remove this comma !
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download