如何解决在 NatTables 中排序
我已经在 nattables 中实现了过滤。如何添加排序?我必须创建新的 columnHeaderLayer
吗?这是我的代码:
1 班BodyLayerStack
class BodyLayerStack extends AbstractLayerTransform {
private final FilterList<TableLine> filterList;
private final SelectionLayer selectionLayer;
private final DataLayer bodyDataLayer;
private final IRowDataProvider<TableLine> bodyDataProvider;
private final SortedList<TableLine> sortedList;
public DataLayer getBodyDataLayer() {
return bodyDataLayer;
}
public SelectionLayer getSelectionLayer() {
return selectionLayer;
}
public IRowDataProvider<TableLine> getBodyDataProvider() {
return bodyDataProvider;
}
从表中获取值:
public BodyLayerStack(List<TableLine> values,IColumnAccessor<TableLine> columnAccessor,Integer[] columnIndicesForRowHeaders) {
EventList<TableLine> eventList = GlazedLists.eventList(values);
TransformedList<TableLine,TableLine> rowObjectsGlazedList = GlazedLists.threadSafeList(eventList);
创建过滤器和排序列表:
this.filterList = new FilterList<>(rowObjectsGlazedList);
this.sortedList = new SortedList<>(filterList,null);
this.bodyDataProvider = new ListDataProvider<TableLine>(this.sortedList,columnAccessor);
bodyDataLayer = new DataLayer(this.bodyDataProvider);
ColumnOverrideLabelAccumulator bodyLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
bodyDataLayer.setConfigLabelAccumulator(bodyLabelAccumulator);
if( columnIndicesForRowHeaders != null ) {
for ( int i = 0; i < columnIndicesForRowHeaders.length; i++ ) {
bodyLabelAccumulator.registerColumnOverrides(
columnIndicesForRowHeaders[i],RowHeaderLabel);
}
}
事件层:
GlazedListsEventLayer<TableLine> glazedListsEventLayer =
new GlazedListsEventLayer<>(bodyDataLayer,this.filterList);
this.selectionLayer = new SelectionLayer(glazedListsEventLayer,false);
selectionLayer.setSelectionModel(new RowSelectionModel<TableLine>(selectionLayer,this.bodyDataProvider,new IRowIdAccessor<TableLine>()
{
@Override
public Serializable getRowId(TableLine line)
{
return line.getId();
}
}));
将配置添加到选择层
selectionLayer.addConfiguration(new DefaultSelectionLayerConfiguration()
{
@Override
protected void addSelectionUIBindings()
{
addConfiguration(new SelectionBindings());
}
@SuppressWarnings("rawtypes")
@Override
protected void addMoveSelectionConfig()
{
addConfiguration(new RowOnlySelectionConfiguration());
}
});
视口层+返回
ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
setUnderlyingLayer(viewportLayer);
}
public FilterList<TableLine> getFilterList() {
return this.filterList;
}
}
解决方法
如果您想通过点击列标题单元格来添加排序,您必须将 SortHeaderLayer
添加到您的列标题层堆栈中。
请检查 NatTable examples,例如 SortableFilterableColumnGroupExample
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。