How do I replace undefined column value to blank string?

How do I replace undefined column value to blank string?

BrettABrettA Posts: 12Questions: 4Answers: 0

Hi, I am running Datatables on a SharePoint 2013 doc library and if a field is empty for a specific item, Datatables displays the value as "undefined".
Can someone please tell me how to replace "undefined" with a "tba" string or blank value or whatever?
I have looked everywhere but cannot find the answer.
Thanks.

This question has an accepted answers - jump to answer

Answers

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

    Hi @BrettA ,

    The way to go is with columns.render, see the examples near the bottom of the page. You can just test for "undefined", and return any other string, such as "tba".

    Cheers,

    Colin

  • BrettABrettA Posts: 12Questions: 4Answers: 0

    Hi Colin, thanks for replying but I cannot see what you are referring to.
    Can you paste the code here, so I can try it please?
    Thanks.

  • bindridbindrid Posts: 730Questions: 0Answers: 119
    Answer ✓

    in cols or columnDefs do something like

    columnDefs:[{targets:[3], render:function(data){if(data == null) {return "tbd"} else {return data}}

  • BrettABrettA Posts: 12Questions: 4Answers: 0

    Thank you bindrid,
    I changed your code a little, used "undefined" and it works now:

    {"render":function(data){if(data == "undefined") {return "tbd"} else {return data}}, "targets": [1,2,3,4] },
    
  • bindridbindrid Posts: 730Questions: 0Answers: 119

    with 2 == signs, the if statement checks for both a null and a undefinded in javascript

This discussion has been closed.