-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Following the documentation of zk demo "Inline Row Editing" I have a grid loading List object. Template that include rows, and each row load each object's value.
Loading each data works fine. However, if I modify one row, all rows in the template are changed. Do I have to create new model for each row?
======my code=======
<grid model="@load(vm.commonVoStatuss)
@template(each.editingStatus ? 'editable' : 'noneditable')"
vflex="1" hflex="1">
<template name="editable">
<textbox value="@load(each.commonSupplierShipmentVo.customerOrderId)
@save(each.commonSupplierShipmentVo.customerOrderId)" />
<textbox value="@load(each.commonSupplierShipmentVo.bookingDate)
@save(each.commonSupplierShipmentVo.bookingDate)" />
Your zul code looks correct. What you missed to provide is the relevant ViewModel code. A common mistake is to @NotifyChange
the whole list-model (re-rendering all rows). In general I'd avoid using @load on a grid/listbox model, unless you really want to replace the ListModel implementation. Preferably use @init(vm.commonVoStatuss)
and replace the contents of the ListModel (add/remove/clear/notifyChange/...).
The "Inline Row Editing"-demo demonstrates how to update a single row in the model.
public void refreshRowTemplate(LanguageContributionStatus lcs) {
//replace the element in the collection by itself to trigger a model update
contributionStatuses.set(contributionStatuses.indexOf(lcs), lcs);
}
Depending on the ZK version you might as well just call contributionStatuses.notifyChange(lcs)
- as a shortcut.
The problem is not on the model. Cause of the problem: My object which will be looped over(commonSupplierShipmentVo) inherit from another class. Probably because in that class equals() and hashCode() is overriden.
When I save one row, all rows are changed because all instances seems to be taken as one instance.
If that's the case (I assume you verified this) then you already know what needs to be done ... either correct the equals/hashcode to differentiate non-equal objects.
Sometimes if you can't change the implementation of your xxxVO
classes then simply wrap them into a (what I call it) row-level-object which follows the equals/hashcode conventions.
If that's the case (I assume you verified this) then you already know what needs to be done ... either correct the equals/hashcode to differentiate non-equal objects.
Sometimes if you can't change the implementation of your xxxVO
classes then simply wrap them into a (what I call it) row-level-object which follows the equals/hashcode conventions.
Asked: 2020-07-27 11:15:53 +0800
Seen: 15 times
Last updated: Aug 07 '20