0

"inline edit" all rows is changed when only one row is modified

asked 2020-07-27 11:15:53 +0800

sharonYu gravatar image sharonYu
1 1

updated 2020-07-28 11:02:01 +0800

cor3000 gravatar image cor3000
5262 2 7
ZK Team

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)" />
delete flag offensive retag edit

4 Answers

Sort by » oldest newest most voted
0

answered 2020-07-28 14:52:35 +0800

cor3000 gravatar image cor3000
5262 2 7
ZK Team

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.

link publish delete flag offensive edit
0

answered 2020-08-07 11:18:29 +0800

sharonYu gravatar image sharonYu
1 1

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.

link publish delete flag offensive edit
0

answered 2020-08-07 11:53:47 +0800

cor3000 gravatar image cor3000
5262 2 7
ZK Team

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.

link publish delete flag offensive edit
0

answered 2020-08-07 11:54:08 +0800

cor3000 gravatar image cor3000
5262 2 7
ZK Team

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.

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2020-07-27 11:15:53 +0800

Seen: 10 times

Last updated: Aug 07

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More