Hanlde null objects in retrieved AJAX data

Hanlde null objects in retrieved AJAX data

mkwatsmkwats Posts: 4Questions: 2Answers: 0

When consifuring the table I get JSON data from server and have the colum data set as:

columns: [
{ data: "LatestStatusRecord.Status", className: 'dt-center', }
]

If there is no LatestStatusRecord i get error becuase LatestStatusRecord.Status will not exisit. What can I do to handle this error? Do I need to do it server side (create the object even if record not exisit) or can I do it the options?

ERROR received
*DataTables warning: table id=TaskTableInner - Requested unknown parameter 'LatestGanttRecord.PercentComplete' for row 0, column 5. For more information about this error, please see http://datatables.net/tn/4*

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 54,897Questions: 1Answers: 8,605 Site admin
    Answer ✓

    Two options:

    1. Make sure that there is a LatestStatusRecord object, or
    2. Use a rendering function which will check it the object exists:
    data: null,
    render: function (data, type) {
      if (! data.LatestStatusRecord) {
        return '';
      }
      return data.LatestStatusRecord.Status;
    }
    

    Allan

  • mkwatsmkwats Posts: 4Questions: 2Answers: 0

    I went with the render option.
    Thank you.

Sign In or Register to comment.