0

I am using datatable to display my data. In one of my columns i am using a render to check the null if it is not null then display the data using split method. The code is working but it gives a browser warning every time it finds a null value.

here is my code

{
  "mData": "address",
  "render": function(data, type, row) {
    if (data == null) { //do nothing}
      else {
        return data.split("\n").join("<br/>");
      }
    }
  }
}

here is the warning message I get

DataTables warning: table id=tblrss - Requested unknown parameter 'address' for row 2, column 5. For more information about this error, please see http://datatables.net/tn/4

4
  • Did you read the information provided in datatables.net/tn/4? Commented Apr 19, 2021 at 14:02
  • Your code, as provided, will give a syntax error and not run. Commented Apr 19, 2021 at 14:02
  • 2
    Each cell in DataTables requests data, and when DataTables tries to obtain data for a cell and is unable to do so, it will trigger a warning, telling you that data is not available where it was expected to be - so give it some data: if (data == null) { return "" }? Commented Apr 19, 2021 at 14:03
  • @freedomn-m thanks yeah i forgot to return anything when it is null, that solve the problem Commented Apr 19, 2021 at 14:08

2 Answers 2

2

Try this

{
  "mData": "address",
  "render": function(data, type, row) {
    return data ? data.split("\n").join("<br/>") : "";
  }
}
Sign up to request clarification or add additional context in comments.

Comments

0
    {
 "mData": "address",
 "render": function(data, type, row) {
  if (data == null) { return "" }
  else {
    return data.split("\n").join("<br/>");
  }
}

//adding something to return when null solved the problem thanks to @freedomn-m

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.