删除过滤器后,添加的行将移动到最后一个位置



在NatTable中,我正在过滤表中添加一行。删除筛选器后,新添加的行将移动到表中的最后一个位置。

但我希望它保持在同一位置,即在筛选表时添加的行旁边。

我目前正在使用RowInsertCommand。我不想通过过去填充表格的模型或列表添加行。我只想通过NatTable命令来实现。有可能吗?

如果没有示例代码,很难理解解释和问题。但我假设您只是从NatTable示例中复制了代码,所以我将在此基础上解释您的问题。

首先,RowInsertCommand有几个构造函数。如果使用的构造函数没有rowIndexrowPosition参数,则新对象将始终添加在列表的末尾。

将NatTable中的过滤器功能与GlazedList一起使用时,封装在主体DataLayer中的列表为FilterList。如果在FilterList上操作以计算应添加新对象的rowIndex,并且在RowInsertCommandHandler中将FilterList作为基本列表,则添加新对象所在的位置将在FilterList和基本EventList之间转换,这可能不是所需的结果。

要解决此问题,您需要使用基础EventList创建RowInsertCommandHandler

EventList<T> eventList = GlazedLists.eventList(values);
TransformedList<T, T> rowObjectsGlazedList = GlazedLists.threadSafeList(eventList);
SortedList<T> sortedList = new SortedList<>(rowObjectsGlazedList, null);
this.filterList = new FilterList<>(sortedList);
this.baseList = eventList;
bodyDataLayer.registerCommandHandler(new RowInsertCommandHandler<>(this.baseList));

执行加法运算的动作当然需要基于基本CCD_ 15来计算索引。以下代码是IMenuItemProviderSelectionAdapter的一部分:

int rowPosition = MenuItemProviders.getNatEventData(event).getRowPosition();
int rowIndex = natTable.getRowIndexByPosition(rowPosition);
Object relative = bodyLayerStack.filterList.get(rowIndex);
int baseIndex = bodyLayerStack.baseList.indexOf(relative);
Object newObject = new ...;
natTable.doCommand(new RowInsertCommand<>(baseIndex + 1, newObject));

最新更新