NatTable在清除数据时保留行选择并重新加载 [英] NatTable preserve row selection on clear data and reload

查看:68
本文介绍了NatTable在清除数据时保留行选择并重新加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码段清除NatTable数据,并在刷新操作时进行完全重新加载.

I use the below snippet to clear the NatTable data and do a complete reload on refresh action.

natTable.getBodyDataProvider().getList().clear();
natTable.getBodyDataProvider().getList().addAll(inputList);
natTable.refresh();

由于数据已清除并重置,因此我无法在刷新之前将行选择设置回先前选择的行.

Since, the data is cleared and reset, I am unable to set the row selection back to previously selected row before refresh.

但是,我正在成功使用RowSelectionModel来恢复对Sort的选择

However, I am using the RowSelectionModel successfully to restore selection on Sort

final RowSelectionModel<T> rowSelectionModel = new RowSelectionModel<T>(bodyLayer.getSelectionLayer(),bodyDataProvider, rowIdAccessor);
bodyLayer.getSelectionLayer().setSelectionModel(rowSelectionModel);

清除并重新加载数据后,是否可以恢复行选择?

Is it possible to restore row selection when data is cleared and reloaded??

我确实在PreserveModel上看到了现有的问题:如何使用星云NatTable的PreserveSelectionModel?a>但是它没有回答我的问题.

I did see existing question on PreserveModel : How to use Nebula NatTable's PreserveSelectionModel? But it did not answer my question.

赞赏是否有人可以提供与此相关的更多指示.

Appreciate if anyone could give more pointers regarding this.

关于,安全数据表

推荐答案

IIRC,当您清除基础列表时(我想您正在使用GlazedLists,因此在执行此操作时会触发一个事件), RowSelectionModel 清除内部存储的选择.这是一致的,因为对已删除的对象进行选择没有任何意义.

IIRC when you clear the underlying list (and I suppose you are using GlazedLists so there is an event fired when you do so), the RowSelectionModel clears the internally stored selections. Which is consistent, as it does not make sense to keep a selection for an object that has been removed.

因此,您需要实施一个解决该问题的解决方法.例如,可以实现自定义的 ISelectionModel ,该自定义 ISelectionModel 扩展了 RowSelectionModel ,并以不同的方式确保与基础列表的一致性.或者,您记得选择内容,然后再清除基础列表,然后再应用选择内容.但是要做到这一点,您需要在NatTable上注册一个 PaintListener ,以延迟应用选择,否则内部事件将延迟清除选择.

So you need to implement a workaround that deals with that fact. That can be for example to implement a custom ISelectionModel that extends the RowSelectionModel and ensures consistency with the underlying list in a different way. Or you remember the selection before you clear the underlying list, and apply the selection afterwards again. But to do this you need to register a PaintListener on NatTable to apply the selection late, otherwise the internal events will clear the selection with a delay.

例如,以下代码段将始终选择NatTable主体区域中的第5行,由于列标题行,该行即是NatTable中的第6行.

The following snippet for example will always select the 5th row in the body region of a NatTable, which is the 6th row in the NatTable because of the column header row.

natTable.addPaintListener(new PaintListener() {

    @Override
    public void paintControl(PaintEvent e) {
        // use column 1 as column 0 in NatTable is the row header
        // insert the rows to select that you previously cached
        natTable.doCommand(
                new SelectRowsCommand(natTable, 1, 5, false, false));
    }
});

这篇关于NatTable在清除数据时保留行选择并重新加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆