Skip to content
This repository was archived by the owner on Feb 2, 2025. It is now read-only.

Table still empty ($resource, $promise, with DataProp) #111

Closed
naxmefy opened this issue Oct 30, 2014 · 5 comments
Closed

Table still empty ($resource, $promise, with DataProp) #111

naxmefy opened this issue Oct 30, 2014 · 5 comments

Comments

@naxmefy
Copy link

naxmefy commented Oct 30, 2014

My JS:

$scope.dtOptions = DTOptionsBuilder
.fromFnPromise(function () {
  return PartyService.query().$promise;
})
.withDataProp('results')
.withOption("bProcessing", true)
.withPaginationType('full_numbers');

$scope.dtColumns = [
  DTColumnBuilder.newColumn('id').withTitle('ID'),
  DTColumnBuilder.newColumn('name').withTitle('Name')
];

My HTML:

<table class="table table-striped table-bordered"
       datatable=""
       dt-options="dtOptions"
       dt-columns="dtColumns"></table>

The Response of Query:

{
    "results": [
        {
           "id": 1,
           "name": "party",
           .....
        },
        ....
     ],
    ....
}

U see i put DataProp to "results" coz results are a nested in object - beside are other infos like count of all parties etc...
ServerSide is a Grails application (but nevermind...)

My table is empty (data is loaded, but empty)... can u maybe explain me what is wrong?

@l-lin
Copy link
Owner

l-lin commented Oct 30, 2014

That's because, when using the promise renderer, angular-datatables is just resolving the promise before adding the data to the DataTable's data option and rendering the table.
So angular-datatables expects an array and not a array inside an object.

In short, AjaxDataProp is useless when using the promise way.

@l-lin l-lin added the question label Oct 30, 2014
@l-lin
Copy link
Owner

l-lin commented Oct 30, 2014

Mmh it might be interesting to add this feature.

@naxmefy
Copy link
Author

naxmefy commented Oct 30, 2014

is it possible to include the data later like this:

PartyService.query(function(data) {
    exampledatatable.add(data.results);
});

@naxmefy
Copy link
Author

naxmefy commented Oct 30, 2014

i did this now and it works

$scope.dtOptions = {};
PartyService.query(function(data) {
    console.log(data);
    $scope.dtOptions = DTOptionsBuilder.newOptions().withOption('aaData', data.results);
});

But i have a new question :D - maybe i generate a ticket later

@l-lin
Copy link
Owner

l-lin commented Oct 30, 2014

Be careful with this. It might have worked because you did not have a large amount of data. So you were "lucky" that the promise was resolved before the DataTable() was called.

l-lin added a commit that referenced this issue Oct 30, 2014
@l-lin l-lin closed this as completed Oct 30, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants