1

I need to make datatable cell "email" as a active link mailto: ...

So, i made something like this:

{ data: 'email',
    "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
        $(nTd).html("<a href='mailto:"+oData.email+"'>"+oData.email+"</a>");
    }
}

This is working, but when the row does not have email, then it will print out as "mailto:null", so I need something like IF statement to check if there is data in that cell. If there is no data then the cell will be left empty.

So, i tried something like below and its not working.

{ data: 'email',
    "fnCreatedCell": if ($('"+oData.email+"').val() != '') { function (nTd, sData, oData, iRow, iCol) {
         $(nTd).html("<a href='mailto:"+oData.email+"'>"+oData.email+"</a>");
    }}
},

How to fix that code?

Regards.

1 Answer 1

1

Place the if inside the function. An if statement cannot be a valid Object value on its own.

"fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
    if (oData.email) $(nTd).html("<a href='mailto:"+oData.email+"'>"+oData.email+"</a>");
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.