-
Notifications
You must be signed in to change notification settings - Fork 490
Server side start with twice request #102
Comments
What version of angular-datatables are you using? |
v0.2.1 |
Mmh...weird, I don't reproduce your issue... Is it related to #101? |
I think it's not related, cause even if I use this way, keep the issue... $scope.dtOptions = DTOptionsBuilder.newOptions()
.withOption('ajax', { url: String.format('{0}api/System/Message/Get', BASEURL) })
.withDataProp('data')
.withOption('serverSide', true); |
In angular-datatables.js at line 375 $scope.$watch('[dtOptions, dtColumns, dtColumnDefs]', function (newVal, oldVal) {
if (newVal !== oldVal) {
var newDTOptions = newVal[0], oldDTOptions = oldVal[0];
// Do not rerender if we want to reload. There are already
// some watchers in the renderers.
if (!newDTOptions.reload || newDTOptions.sAjaxSource !== oldDTOptions.sAjaxSource) {
//IT PASS HERE 2x
ctrl.render($elem, ctrl.buildOptions(), _staticHTML);
} else {
// The reload attribute is set to false here in order
// to recall this watcher again
newDTOptions.reload = false;
}
}
}, true); I console.log it, and I saw it pass 2x... Is it right? |
I made a Plnkr and it's not calling twice. Can you edit this plnkr to reproduce your issue? |
I'll try! 2014-10-22 16:07 GMT-02:00 Louis LIN [email protected]:
Att. |
Hi, I fixed this bug by placing the line _render(options, $elem, $scope); inside the if (angular.isDefined(sAjaxSource)) { condition. Here is the final result : $scope.$watch('dtOptions.sAjaxSource', function (sAjaxSource) {
if (angular.isDefined(sAjaxSource)) {
_this.options.sAjaxSource = sAjaxSource;
if (angular.isDefined(_this.options.ajax)) {
if (angular.isObject(_this.options.ajax)) {
_this.options.ajax.url = sAjaxSource;
} else {
_this.options.ajax = { url: sAjaxSource };
}
}
_render(options, $elem, $scope);
}
}); But I don't know if there was a specific reason to have the render outside the condition ?? Dear, |
It doesn't worked for me! I saw that at line 1089 if (oTable) {
var ajaxUrl = options.sAjaxSource || options.ajax.url || options.ajax;
oTable.ajax.url(ajaxUrl).load();
} else {
oTable = DTRendererService.renderDataTableAndEmitEvent($elem, options, $scope);
} When the component starts, it passes sequentially in the 'else' and soon after the 'if'. |
That's right! This is cause by the watch statements : $scope.$watch('dtOptions.sAjaxSource', function (sAjaxSource) {
if (angular.isDefined(sAjaxSource)) {
_this.options.sAjaxSource = sAjaxSource;
if (angular.isDefined(_this.options.ajax)) {
if (angular.isObject(_this.options.ajax)) {
_this.options.ajax.url = sAjaxSource;
} else {
_this.options.ajax = { url: sAjaxSource };
}
}
_render(options, $elem, $scope);
}
});
$scope.$watch('dtOptions.reload', function (reload) {
if (reload) {
$scope.dtOptions.reload = false;
_render(options, $elem, $scope);
}
}); In fact Angular JS notifies that dtoOptions.sAjaxSource has changed (but it's undefined), then AngularJs notifies that dtoOptions.reload has changed (because that's the first load I think. In reallity, you have 2 calls to the _render method sequentially.... That's why the first call passed by the else statement and the second by the if statement (the oTable has been initialized by the first call). I Moved the _render method because sAjaxSource is always undefined because I used the { url: '', method: 'post' } configuration instead. Dear |
Where you changed the code? Remove or replace something? |
OK, I'm using V0.2.0 and my changes were made on line 1047. $scope.$watch('dtOptions.sAjaxSource', function (sAjaxSource) {
if (angular.isDefined(sAjaxSource)) {
_this.options.sAjaxSource = sAjaxSource;
if (angular.isDefined(_this.options.ajax)) {
if (angular.isObject(_this.options.ajax)) {
_this.options.ajax.url = sAjaxSource;
} else {
_this.options.ajax = { url: sAjaxSource };
}
}
}
_render(options, $elem, $scope);
}); Was changed to : $scope.$watch('dtOptions.sAjaxSource', function (sAjaxSource) {
if (angular.isDefined(sAjaxSource)) {
_this.options.sAjaxSource = sAjaxSource;
if (angular.isDefined(_this.options.ajax)) {
if (angular.isObject(_this.options.ajax)) {
_this.options.ajax.url = sAjaxSource;
} else {
_this.options.ajax = { url: sAjaxSource };
}
}
_render(options, $elem, $scope);
}
}); |
Oh man, i am using v0.2.1, and this code snippet does not exists anymore! :( |
Sorry, I'm trying with V0.2.1. But i've got some errors. I come back to you after fixing it. |
OK, I tested with V0.2.1 and it looks good :) thank you. |
With V0.2.1 this problem was solved to you? |
Yes but i've got anothre bug using the reloadData functionnality but I cannot isolate the root cause |
This issue was solved? |
You're right! 2014-11-27 11:33 GMT-02:00 Louis LIN [email protected]:
Att. |
Hi, I'm seeing the same issue in v0.4.3. |
It is because of the promises. In the first load of your page, you must set the // I personally don't like this approach. It should have been handled by the directive already
vm.tableOptions = $q.defer().promise;
vm.tableColumns = $q.defer().promise;
// After Loading the DOM, add your options
vm.tableOptions = DTOptionsBuilder ... // or $resource().query().$promise;
vm.tableOptions = DTColumnsBuilder ... // or $resource().query().$promise; This is what I noticed, if the DOM is not yet ready, the tableOptions will attempt to call for an ajax request, but since the |
I'm using with server side processing and when it initializes, the request to server is duplicated.
The text was updated successfully, but these errors were encountered: