DatatablesForEach-Custom-Knockout-Binding icon indicating copy to clipboard operation
DatatablesForEach-Custom-Knockout-Binding copied to clipboard

Attempting to update view model object for object whose data isn't being shown in grid doesn't display

Open cholt0425 opened this issue 9 years ago • 2 comments

Using datatables 1.10 and knockout 3.4. The problem is, if you manipulate a view model item when that view model item is not on the current page the DataTable is displaying, the value will not be reflected in the DataTable when going to the page the item is on. So say you have a simple object reflected in the Datatable with a string and a bool and that data is tied to a text column and a checkbox. If you set the object bool to true and that item is on say page 2 of the datatable. When you go to page 2 the checkbox will be not checked. I believe it has something to do with the fact that the html elements are only physically on the html page when viewing that page of data in the DataTable.

Example object:

function PickerItem(data) { var self = this; self.id = ko.observable(data.Id); self.name = ko.observable(data.Name); self.selected = ko.observable(data.Selected); }

If page as a list of these that are bound to the tbody using the binding and you modify the last one in the list (assuming) list is greater than page size and then navigate to the second page of Datatables the modification will not be shown.

cholt0425 avatar Feb 17 '16 19:02 cholt0425

Yes... I verified that this is indeed an issue... I won't be able to work on this any time soon. I did get things to work properly via subscriptions but didn't get to cleaning it up in an elegant way. So feel free to fix this issue If you'd like. What I basically did was used the subscription to destroy and re-initialize the datatable when the value changed... Another thing to consider is that this is only an issue with. datatables paging. This is becuase the html is dynamic and knockout just doesn't play well with dynamic html. The issue goes away if you do not use datatables paging.

zachpainter77 avatar Mar 09 '16 20:03 zachpainter77