NatTable - 排序时的奇怪行为

NatTable - Strange behavior when sorting

我有一个 nattable 具有 sort/filter 能力基于 http://www.eclipse.org/nattable/documentation.php?page=sorting 和示例 6031_GlazedListsFilterExample.java

最初我的 table 有零行。

场景 1:

场景 2:

场景 3:

在NatTable的初始'view'之后,第header列动作不是'updated'是有原因的吗?换句话说,在第一次查看 NatTable 之后,它似乎将 presence/absence 行考虑到了 table 的剩余生命周期,而不管行是否更改。

相关代码部分如下所示:

private CompositeLayer createExampleLayer(Collection<T> values, 
  IColumnPropertyAccessor<T> columnPropertyAccessor,
  IDataProvider columnHeaderDataProvider, IConfigRegistry 
  configRegistry, Matcher<T> matcher) {
    BodyLayerStack<T> bodyLayerStack = new BodyLayerStack<>(
      values, columnPropertyAccessor);

    // build the column header layer
    DataLayer columnHeaderDataLayer = new 
      DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
    ILayer columnHeaderLayer = new 
      ColumnHeaderLayer(columnHeaderDataLayer, bodyLayerStack,
      bodyLayerStack.getSelectionLayer());

    SortHeaderLayer<T> sortHeaderLayer = new SortHeaderLayer<>
      (columnHeaderLayer, new GlazedListsSortModel<T>
      (bodyLayerStack.getSortedList(), columnPropertyAccessor, 
      configRegistry,                      
      bodyLayerStack.getBodyDataLayer()), false);

    FilterRowHeaderComposite<T> filterRowHeaderLayer = new 
      FilterRowHeaderComposite<>(
        new DefaultGlazedListsFilterStrategy<T>
         (bodyLayerStack.getFilterList(), columnPropertyAccessor,
         configRegistry),
       sortHeaderLayer, columnHeaderDataLayer.getDataProvider(), 
       configRegistry);

    // Omitted code for rowHeaderLayer and cornerLayer
    return new GridLayer(bodyLayerStack, filterRowHeaderLayer, 
    rowHeaderLayer, cornerLayer);
}

public BodyLayerStack(Collection<T> values, 
  IColumnPropertyAccessor<T> columnPropertyAccessor) {
    eventList = GlazedLists.eventList(values);

    TransformedList<T, T> rowObjectsGlazedList = 
      GlazedLists.threadSafeList(eventList);

    this.sortedList = new SortedList<>(rowObjectsGlazedList, null);

    // wrap the SortedList with the FilterList
    this.filterList = new FilterList<>(sortedList);
    this.bodyDataProvider = new ListDataProvider<>(this.filterList, 
      columnPropertyAccessor);
    this.bodyDataLayer = new DataLayer(getBodyDataProvider());

    // layer for event handling of GlazedLists and PropertyChanges
    GlazedListsEventLayer<T> glazedListsEventLayer = new 
      GlazedListsEventLayer<>(bodyDataLayer, this.filterList);

    this.selectionLayer = new SelectionLayer(glazedListsEventLayer);
    ViewportLayer viewportLayer = new ViewportLayer(getSelectionLayer());

    setUnderlyingLayer(viewportLayer);
}

private void enableSorting() {
    this.nattable.addConfiguration(new SingleClickSortConfiguration());
}

看起来您的 SortHeaderLayer 创建不正确。 GlazedListsSortModel 的最后一个参数需要是 header 列的 IDataLayer,而不是 body 层。

将您的代码更改为以下内容应该可以正常工作。至少对我来说是这样。

SortHeaderLayer<T> sortHeaderLayer = new SortHeaderLayer<>
  (columnHeaderLayer, new GlazedListsSortModel<T>
  (bodyLayerStack.getSortedList(), columnPropertyAccessor, 
  configRegistry,                      
  columnHeaderDataLayer), false);