简体   繁体   English

排序2个不同的数据网格

[英]Sorting of 2 different datagrids

Is it possible to sync two different datagrids that contains similar values columns? 是否可以同步两个包含相似值列的不同数据网格? (I can put it on a single datagrid, but I plan to do something else.) (我可以将其放在单个数据网格上,但我打算做其他事情。)

That is, if I sort datagrid 1, datagrid 2 will also sort. 也就是说,如果我对datagrid 1进行排序,那么datagrid 2也将进行排序。

Yes. 是。

You can add a ColumnSortHandler to one Datagrid. 您可以将ColumnSortHandler添加到一个Datagrid。 In this handler you can call event.getColumn() to see which column has been used for sorting, and event.isSortAscending() to get the direction of the sort. 在此处理程序中,您可以调用event.getColumn()以查看用于排序的列,以及event.isSortAscending()可以获取排序的方向。 Then you can push the corresponding column to the sort list in the other Datagrid and call a sort event on it: 然后,您可以将相应的列推到另一个Datagrid中的排序列表中,并在其上调用一个排序事件:

tableA.addColumnSortHandler(new ColumnSortEvent.Handler() {

    @Override
    public void onColumnSort(ColumnSortEvent event) {
        Column<MyObject, String> columnA = event.getColumn();
        // find columnB in tableB that corresponds to columnA in tableA
        tableB.getColumnSortList().push(new ColumnSortInfo(columnB, event.isSortAscending()));
        ColumnSortEvent.fire(tableB, tableB.getColumnSortList());
    }
});

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

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