1

I am trying to display the Assigned To field in a table I am making with REST in SharePoint but all that is getting returned is [object Object]. When I type this url into my website I can see the name of the person assigned to but it still does not show up in my table. Here is the code, all the other categories are displaying. Any help would be greatly appreciated.

<script type="text/javascript">

function LoadTasks()
{
    var call = $.ajax({
        url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/Lists/GetByTitle('Tasks')/items?$select=Title,DueDate,OData__Author,Priority,AssignedTo/Title&$expand=AssignedTo",
        type: "GET",
        dataType: "json",
        headers: {
            Accept: "application/json;odata=verbose"
        }

    });
    call.done(function (data,textStatus, jqXHR){
        $('#example').dataTable({
            "bDestroy": true,
            "bProcessing": true,
            "aaData": data.d.results,
            "aoColumns": [
                { "mData": "Title" },
                { "mData": "DueDate" },
                { "mData": "OData__Author" },
                { "mData": "Priority" },
                { "mData": "AssignedTo" }
            ]
          });
    });
    call.fail(function (jqXHR,textStatus,errorThrown){
        alert("Error retrieving Tasks: " + jqXHR.responseText);
    });
}
LoadTasks()
</script>

1 Answer 1

1

AssignedTo in your example is a plain object (with Title property), not a string. DataTables probably tries to call the toString of the object, which will be [object Object].

The best solution I can think of: mData should support deeply nested objects, so try { "mData": "AssignedTo.Title" }:

...
"aoColumns": [
    { "mData": "Title" },
    { "mData": "DueDate" },
    { "mData": "OData__Author" },
    { "mData": "Priority" },
    { "mData": "AssignedTo.Title" }
]
...

If this does not work you could try to map data.d.results, like this (ES5):

var data = data.d.results.map(function(item) {
  item.AssignedTo = item.AssignedTo.Title;
  return item;
});

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.