Hello,
I’ve tried to edit a Backbone Collection using the DataTable component. It shows the data, and allow to edit them. But it does not store the updated values back to the collection. Why?
Sincerely,
Sergey Zyryanov
Hello,
I’ve tried to edit a Backbone Collection using the DataTable component. It shows the data, and allow to edit them. But it does not store the updated values back to the collection. Why?
Sincerely,
Sergey Zyryanov
I have same problems with DataTable component!
Please check the next sample.
http://webix.com/snippet/a6193ef4
If you have used “sync” command, the collection will be updated after edit operations in grid ( the usage of WebixView is optional, you can use standalone components as well )
Beware that while updating the collection, component will not trigger automatic data saving to the database. You need to add the handlers for it, check “Data saving” section in the next article
http://docs.webix.com/desktop__backbone_collections.html
if it still doesn’t work for you - please provide any kind of sample ( you can alter the above one ) and info about used version of Backbone
If you are loading data in different way, or expect some different reaction after edit operation - please describe the details.
maksim,
Thank you for explanation. Yet I must apologise because I forgot to mention important details. My Backbone Model overrides the get() and set() methods because of the complex data nature. Please look a the following sample:
http://webix.com/snippet/c5cd083f
You can click the “Show first comment” button to invoke the overriden get() method, and click the “Change first comment” button to invoke the set() method. Both methods seems correct, but DataTable does not uses the methods for the “comment” column.
According to the backbone’s documentation, set method must accept both key-value pair and hash object. Webix component do provide hash object, which is ignored by the code of custom setter.
You can extend the code of model like next
http://webix.com/snippet/b062fef9 ,
so the setter will support the hash parameter.
On other hand, we can update the code of Webix, so code will call separate set command for each parameter in the data object. Updated code will work fine for simple edit scenario, but in some cases, when multiple fields changed at once, it will result in multiple “change” events on backbone model. Not quite sure about this decision.
Thank you very much! Your update setter code is fine, and you don’t needed to update the Webix code, of course.
But there still be a custom getter issue. As you can see on the sample code, the custom getter returns “comment1” and “comment2” values for the first and second rows respectively. But DataTable shows empty cells instead. Can you please suggest me any workaround?
Also, it seems that DataTable does not process the colloction’s “reset” event:
http://webix.com/snippet/6d832d63
Try to click the “Reset collection” button. You will see that the data is changed, but the DataTable is not updated.
I can confirm the problem with getters. Currently Webix uses model.attributes collection directly. In next update we will change the behavior of sync method, so it will use model.get logic. As temporary workaround you can define the data mapping as property of datatable. ( map property for related column in the datatable )
http://webix.com/snippet/5b947230
update:
It appears to be a more complicated issue. We will look how to solve it in the future. The next build will provide the partial solution. It will be possible to use the next syntax
view.root.sync(films, { get:"title,comment" });
such commands explictly defines which fields must be shared between model and WebivView. In such case getters will be processed correctly and component will be able to access and modify only the listed fields.
Problem with “reset” confirmed as well, fix will be released as part of the next build.
Thank you in advance!