-
Notifications
You must be signed in to change notification settings - Fork 490
Cannot Reinitialise DataTable #1160
Comments
I assume you are calling next() when the websocket updates the table? If so, you must destroy the table first before calling next(). Also try draw() on the dt instance instead to redraw after updating the data. I had to use setTimeout though to let angular update the DOM first then call draw() |
@ljmerza thanks for your reply. I'm not calling any next() or draw() method at any place. This is what I actually do when receive notification:
And you can see in the HTML code given above in the question that I'm showing the same list (in which I'm pushing an element after receiving notification) with ng-repeat in HTML file. Please let me know If I'm missing anything which I need to add. |
You do need to call rerender when adding items to the array. Sure, Angular updated the DOM but Angular didn't notify datatables that the DOM updated http://l-lin.github.io/angular-datatables/archives/#!/rerender |
Is this the reason that I'm getting Cannot Reinitialise DataTable error? |
This example should be close to what you want. |
@ljmerza @l-lin First Thing:
Second Thing: Third Thing: So, with all the options tried so far, I'm getting an error that when I add/remove data randomly based upon the async notification on web socket, sometimes table gets disordered and all the data gets disappears. |
@ljmerza @l-lin I dig into this further and found some more information related to issues being faced. Whenever I try to add/remove rows quickly (by adding data into the list bonded with table) or I add 2 rows then datatable gets disappear completely. If there are a lot of issues then why unstable things are released or documentation isn't that much matured? |
Hi guys @bilalahmed54 @l-lin, I seem to have a very similar problem to this one (angular-datatables version 0.6.2) @vinodf recomended a fix in his post here: #262 (comment) which helped to fix mine problem. Could you give it a try? If it helps we could perhaps try to persuade @l-lin to fix it in the code base. Regards, Roman |
Unfortunately, this fix solves some issues, but it also bring regression to other functionnalities, such as changing the data with the angular renderer. |
Hi Luis, yes you are right. Please have a look at the second version of the fix: Probably not an ideal fix, but it works. In particular I was wondering what is the purpose of the _alreadyRendered variable and if it has anything to do with the problem. Anyway, to the cause of the problem: it manifests when there is more than one successive change to the datatable's data (e.g. resizing the collection twice). Normally a change to the datatable's data trigger the _parentScope.$watchCollection(...) callback function. The callback function destroys the table and schedules an another callback via $timeout() which in turn creates the underlying datatable. Seems fine. What I mean by "_parentScope.$watchCollection(...) callback function" is this. The code directly:
Now, let's assume we have two successive changes to the size of the data. The way the _parentScope.$watchCollection(...) callback function is written expects that the $timeout() callback function will be executed rather SOON after the execution of the _parentScope.$watchCollection(...) callback stops. Something like this: _parentScope.$watchCollection(...) callback (change 1) Howewer, this order is NOT guaranteed and depends on many circumstances, so the execution order may look like this: _parentScope.$watchCollection(...) callback (change 1) Which causes the underlying datatable to be initialized twice - and it complains. Hope it makes sense. Regards, Roman |
Thanks @rhorenov for your analyze. I commited your fix and I removed the flag |
Hi - I have the same issue as the OP - please could this fix be released? |
My bad, totally forgot. I released the v0.6.3. |
Uh oh!
There was an error while loading. Please reload this page.
I have a WebSocket connection that updates my tables if there is a change in a row data, when the WebSocket get the message of the change, the code do the work and splice and push the data to the model bound with table, and I have to use $scope.$apply() to see the visual update, and after using $apply the table disappear from the view.
This is how I am initializing my data table:
And below id my HTML code:
I am using the following bower dependencies:
And this is the exact message I get in the pop-up:
And after this error table is disappeared and I had to refresh the page to get it in its actual shape. Any help would be highly appreciated.
The text was updated successfully, but these errors were encountered: