Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested data objects don't work when loading a table via a promise. #214

Closed
dtychshenko opened this issue Feb 9, 2015 · 1 comment
Closed
Labels
Milestone

Comments

@dtychshenko
Copy link

When loading a data table through a promise, the .withDataProp() option does not seem to work with nested objects. For example:

Options:

vm.dtOptions = DTOptionsBuilder.fromFnPromise(function() {
        return $resource('data-nested.json').get().$promise;
    }).withDataProp('data.inner');

Data (data-nested.json):

{
    "data": {
        "inner": [
            {
                "id": 860,
                "firstName": "Superman",
                "lastName": "Yoda"
            }, {
                "id": 870,
                "firstName": "Foo",
                "lastName": "Whateveryournameis"
            }, {
                "id": 590,
                "firstName": "Toto",
                "lastName": "Titi"
            }
        ]
    }
}

Results in this error:

 TypeError: Cannot convert undefined or null to object
    at _doRender (angular-datatables.renderer.js:322)
    at angular-datatables.renderer.js:312
    at processQueue (angular.js:12984)
    at angular.js:13000
    at Scope.$get.Scope.$eval (angular.js:14200)
    at Scope.$get.Scope.$digest (angular.js:14016)
    at Scope.$get.Scope.$apply (angular.js:14304)
    at done (angular.js:9518)
    at completeRequest (angular.js:9703)
    at XMLHttpRequest.requestLoaded (angular.js:9646)

It seems the problem is in angular-datatables.renderer.js line 309:

// In case the data is nested in an object
if (renderer.options.sAjaxDataProp) {
    data = result[renderer.options.sAjaxDataProp];
}

I'll submit a pull request with a fix for this issue.

dtychshenko pushed a commit to dtychshenko/angular-datatables that referenced this issue Feb 9, 2015
@l-lin
Copy link
Owner

l-lin commented Feb 9, 2015

Merged. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants