【问题标题】:Vaadin Flow Grid. How to select one row programmatically?Vaadin 流网格。如何以编程方式选择一行?
【发布时间】:2019-01-13 11:32:30
【问题描述】:

我尝试在网格中使用键箭头实现导航。

为此,我需要能够以编程方式为每个行索引选择一行。

我该怎么做?

谢谢。

【问题讨论】:

    标签: vaadin10 vaadin-flow


    【解决方案1】:

    Vaadin Flow Grid 有方法 Grid.select(item),它以编程方式选择项目。所以你需要解决这个项目。获取它的最佳方法是使用 Grid.getDataCommunicator() ,它具有以下方法 fetchFromProvider:

    https://demo.vaadin.com/javadoc/com.vaadin/vaadin-core/10.0.2/com/vaadin/flow/data/provider/DataCommunicator.html#fetchFromProvider-int-int-

    所以 fetchFromProvider(rowIndex,1) 返回您要选择的项目。

    【讨论】:

    • 谢谢,这个方法是受保护的,我不能这样做 grid.getDataCommunicator().fetchFromProvider(1,1);请给我一个完整的例子吗?
    • 感谢您指出这一点。在 Vaadin 8 中,等效方法是公开的,因此我没有注意到这一点。
    【解决方案2】:

    您可以使用您的网格定义的 SelectionModel。

    private Grid<Customer> customerGrid = new Grid<>();
    customerGrid.getSelectionModel().select([enter your logic for identifying the customer of your wish]);
    

    【讨论】:

      【解决方案3】:

      使用以下 API(自 Vaadin 17 起)

      Person item = grid.getDataCommunicator().getItem(42);
      grid.select(item);
      

      Person item = grid.getGenericDataView().getItem(42);
      grid.select(item);
      

      【讨论】:

        猜你喜欢
        • 2011-04-03
        • 1970-01-01
        • 2016-01-13
        • 1970-01-01
        • 2015-11-01
        • 2012-02-16
        • 2019-01-24
        • 1970-01-01
        • 2015-11-12
        相关资源
        最近更新 更多