简体   繁体   English

在 nattable 中动态更改列和数据 model 的正确方法是什么?

[英]What is the correct way to dynamically change columns and data model in nattable?

When changing the number of columns and rows of natTable After clearing the column list of DataProvider, create a new column item and change the column item list of columnPropertyAccessor.更改natTable的列数和行数时,清除DataProvider的列列表后,新建一个列项,更改columnPropertyAccessor的列项列表。 Then, put the new data model into the filter list and refresh it.然后,将新数据 model 放入过滤器列表并刷新。

When the 7-column nattable is sorted (ascending or descending) and clicked, it is changed to a different data model (4 columns) as above, but if it is sorted, " CurrentModificationException " and " IndezxOutOfBoundException " occur.当 7 列的 nattable 排序(升序或降序)并单击时,它会更改为与上述不同的数据 model(4 列),但如果排序,则会出现“ CurrentModificationException ”和“ IndezxOutOfBoundException ”。 If you exchange data models without sorting, there is no problem.如果您交换数据模型而不进行排序,则没有问题。 I don't know which part is causing it.我不知道是哪个部分造成的。

Is my way of replacing the filter list wrong when changing the data model?更改数据 model 时,我替换过滤器列表的方式是否错误? If anyone has encountered a similar error and has solved it, please help.如果有人遇到过类似的错误并解决了,请帮忙。

Well you don't show how you are doing things, so I can't tell any details.好吧,你没有展示你是如何做事的,所以我不能告诉任何细节。 But to answer your question, yes I think you are doing things wrong.但要回答你的问题,是的,我认为你做错了。

In short, if you have a state applied according to a column like sorting or filtering and you change the underlying data structure, things will break as the states does match the structure anymore.简而言之,如果您根据排序或过滤之类的列应用了 state 并且您更改了基础数据结构,那么随着状态不再与结构匹配,事情就会中断。 Not sure why you think this should work automatically.不知道为什么你认为这应该自动工作。

If you change the underlying data structure you need to clear structure based states in advance.如果更改底层数据结构,则需要提前清除基于结构的状态。

There is an example in the NatTable examples application that shows how to change the data provider dynamically. NatTable 示例应用程序中有一个示例显示如何动态更改数据提供者。 Not sure if the example covers the clearing of states or if this is handled automatically when you are doing things correctly.不确定该示例是否涵盖状态清除,或者当您正确执行操作时是否会自动处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM