Column Reading Data as [object Object]

Column Reading Data as [object Object]

zgoforthzgoforth Posts: 473Questions: 87Answers: 2
edited August 24 in DataTables 1.10

I am using a SharePoint Person/Group field pulling through a rest API to try and populate to my column as the main dataSrc for rowGroup, so I am curious if that is getting effected as well.

Here is the property path to get to the nested value, I just cannot figure out how to get it to work with the column?

d.results[0].AssignedTo.results[0].Title

& for the other item that I have listed in my response it is this:

d.results[1].AssignedTo.results[0].Title
    var table = $('#taskTable').DataTable({
    columns: [
    {"data": "AssignedTo.results[0].Title", visible: false },
    {"data": "Priority", visible: false},
    {"data": "Title"},
    {"data": "Status"},
    {"data": "StartDate",
    render: function(data, type, row) { //render function to format the date values from my AJAX 
            if (type === "sort" || type === "type") {
                return data;
            }
            return moment(data).format("MM/DD/YYYY");
            }
    },
    {"data": "DueDate",
    render: function(data, type, row) { //render function to format the date values from my AJAX 
            if (type === "sort" || type === "type") {
                return data;
            }
            return moment(data).format("MM/DD/YYYY");
            }
    },
    {"data": "PercentComplete"}
  ],
  dom: 'frt',
  columnDefs: [ {
            orderable: false,
            className: 'select-checkbox',
            targets:   0
        } ],
  select: true, 
  order: [[2, 'asc']],
          rowGroup: {
                dataSrc: [
                    'AssignedTo',
                    'Priority'
                ],
                startRender: function(rows, group, level) {
                    var all;
                    if (level === 0) {
                        top = group;
                        all = group;
                    } else if (level === 1) {
                        parent = top + group;
                        all = parent;
                        // if parent collapsed, nothing to do
                        if (!collapsedGroups[top]) {
                            return;
                        }
                    } else {
                        // if parent collapsed, nothing to do
                        if (!collapsedGroups[parent]) {
                            return;
                        }
                        all = top + parent + group;
                    }
                                        
                    var collapsed = !collapsedGroups[all];
                    //console.log('collapsed:', collapsed);
    
                    rows.nodes().each(function(r) {
                        r.style.display = collapsed ? 'none' : '';
                    });
                    
                    var priorityClass = '';
                    
                    rows.every(function (rowIdx, tableLoop, rowLoop, data){
                      var data = this.data();
                      var api = $.fn.dataTable.Api('#taskTable');
                        //console.log(api);

                      //console.log(data.Priority)
                    switch(data.Priority){
                        case '(1) High':
                            priorityClass = 'red';
                          break;
                        case '(2) Normal':
                            priorityClass = 'orange';
                          break;
                        case '(3) Low':
                            priorityClass = 'yellow';
                          break;
                      }
                        
                    });
                    //Add category name to the <tr>.
                    
                    if(level === 0){
                    return $('<tr/>')
                        .append('<td colspan="6" style="text-align: left;">' + group + ' (' + rows.count() + ')</td>')
                        .attr('data-name', all)
                        .toggleClass('collapsed', collapsed);
                    } else if (level === 1) {
                    return $('<tr/>').addClass(priorityClass)
                        .append('<td colspan="6" style="text-align: left;">' + group + '</td>')
                        .attr('data-name', all)
                        .toggleClass('collapsed', collapsed);
                    }
                    
    
    
                }
    
            }
});

This question has an accepted answers - jump to answer

Answers

  • zgoforthzgoforth Posts: 473Questions: 87Answers: 2
    Answer ✓

    Disregard it was because of the dataSrc

Sign In or Register to comment.