1.9.1 and Knockout.js ViewModel binding appears broken
1.9.1 and Knockout.js ViewModel binding appears broken
bdetchison
Posts: 6Questions: 0Answers: 0
I believe the 1.9.1 update has broken interoping with Knockout.js viewmodels
I have set up 1 jsfiddles 1 for 1.9.0 and 1 for 1.9.1;
1.9.0 seems to work fine with Knockout.js I have a jsfiddle here. http://jsfiddle.net/bdetchison/b4SsE/.
1.9.1 seems to not update when Knockout.js's ViewModel has changed. Here is a jsfiddle. http://jsfiddle.net/bdetchison/27DZR/
**Edit
moved to bug reports
I have set up 1 jsfiddles 1 for 1.9.0 and 1 for 1.9.1;
1.9.0 seems to work fine with Knockout.js I have a jsfiddle here. http://jsfiddle.net/bdetchison/b4SsE/.
1.9.1 seems to not update when Knockout.js's ViewModel has changed. Here is a jsfiddle. http://jsfiddle.net/bdetchison/27DZR/
**Edit
moved to bug reports
This discussion has been closed.
Replies
The 1.9.1 link had a 404 error on it when trying to load the DataTables source. That resulting in a JS error when the KO binding tried to initialise the table. I've just updated the 1.9.1 example with a link to the 1.9.1 source and it seems to work as expected: http://jsfiddle.net/27DZR/3/ :-)
Let me know if you have any other issue with it!
Allan
Thanks!
https://github.com/DataTables/DataTables/commit/814ce1f7d57c92cb543a1aa027fc5190f8929655
Removing that added line allows the knockout bindings to go back to how they were. Equally, if you modify a few lines before, where aDataIn is defined as an extended object - if you don't extend the object, then it works as expected in DataTables 1.9.1.
In retrospect I don't like that clone - it was there to match the slice() on the arrays, which in turn was there because fnRender can modify the source data (which I liked even less than slicing the array). I'm thinking of adding an option to DataTables to disable that clone, which would allow easier and tighter integration with libraries such as knockout and backbone. However, I'll keep digging and see if this is a bug or an unintended consequence and will require the new feature to address it.
Allan
The problem is detailed there, but basically my change is overwriting the bindings :-(. Needs some thought on the best way to do this (and I need to get my finger out and make some time to play with Knockout properly!).
Allan
much appreciated!
Allan
Basically every one of our pages are going to have a knockout view model associated with it, in some cases more if we have single page apps. if we dont have the model binder (cogshift), if we had a row addition, for example, we would have to enter the row into the view model array and then add a row to datatables. Thats a bummer because the whole idea is the UI would sit on top of the VM and the only thing we would need to worry about is the VM, the UI updating would get taken care of by itself with KO observables.
To complicate things even further we are using a signaling framework (SignalR) to asynchronously update our viewmodel which in turn should update the datatable, but again the idea was signalr could just update our KO viewmodel and the ui would update accordingly.
Its beautiful to see all these technologies work together. :)
EDIT:
Just to clarify, with the 1.9.0 version the only thing we do is initialize datatables and use the VM to handle everything as far as updating/inserting/deleting the array that datatables is using.
[code]
[/code]
So the main goal here is to use the observable objects/values - when you change a value, the value will be changed in the DataTables. Order, filtering and paging will all be done with DataTables - does that sound about right.
That sounds perfectly feasible :-)
Allan
Allan
This I think is how DataTables will be able to integrate with Knockout and similar libraries. At least that's the plan. Haven't had time to test it yet, but invalidate() at least will be in 1.10!
The changes are in git if anyone is feeling brave - in the 1_10_wip branch. The API is almost complete now, so unit tests will follow shortly, and hopefully a release in a not too distant future. During the betas, I'll attempt to get an integration example with Knockout going.
Allan