如何访问组件列?
我有一个添加一个组件列的网格。对于每行,我在该列上设置一个图标。
因此,可能有图标“ plus”的第1行,并带有图标“打印”第2行。 我需要根据那些图标对网格进行排序,例如单击列,并首先带有“打印”图标的所有行,稍后使用“ Plus”图标的图标,反之亦然。
我找不到一种访问具有特定图标编程的行的方法,而列甚至不是基础数据提供商的一部分。它不仅是图标。要使用它并用列替换为存储整数的列。通过迭代该网格或DataProvider,无法通过迭代来获得该值。
我想这样做。对它们进行排序。在具有“ plus”图标的行上环上,以在基础数据集或网格上的字段/列中分配值1,而对于“ print''分配0。 我想这样做,以便我可以按该值对行进行排序。因此,第0行首先出现,然后再进行1行,因为我认为这是这样做的方式。
很抱歉,如果听起来确实令人困惑,但是本质上,我需要找出如何使用Vaadin访问一排的字段/列,并在基础数据集中更改该值,或访问网格上的行并获取列值。
另外, AddComponentColumn 和 AddColumn 有什么区别?
I have a grid to which I add a component column.For each row I set an icon on that column.
So there might be row 1 with icon 'plus' and row two with icon 'print'.
I need to sort the grid according to those icons like clicking on the column and bring all rows with 'print' icons first and those with 'plus' icon later,or vice versa.
I can't find a way to access the rows that have a certain icon programmaticaly, while the column is not even part of the underlying data provider.It's not just icons.Take that away and replace it with a column say that stores Integers.There's no way to get that value by iterating through that grid or dataprovider.
I want to do that for sorting them.Loop over the rows that have the 'plus' icon to assign value 1 in an adjustent (artificial?) field in the underlying dataset or field/column on grid,while for those with 'print' assign the value of 0.
I want to do that so I can sort the rows by that value.So rows with 0 come first and rows with 1 later on,because I think that's the way of doing it.
I'm sorry if it does sound rather confusing,but in essence I need to find out how you can with Vaadin access a field/column of a row and change that value in the underlying dataset,or access the row on the grid and get the column value.
Also what is the difference between addcomponentcolumn and addcolumn?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在从错误的方向来解决这个问题。您的组件渲染器正在使用一些数据来确定要渲染的图标。因此,您希望根据使用的数据确定渲染图标,而不是检查已渲染的图标,而是要对网格进行排序。检查单元格的渲染内容也不适用于大型网格,因为该组件仅呈现当前在视口中可见的行,而排序应考虑所有行。
文档中有一个示例演示了如何在使用自定义渲染器的列上设置排序比较器(链接部分中的第二个示例): https://vaadin.com/docs/latest/ds/components/grid/prid/#sorting 。
链接示例中的示例代码:
You are approaching that problem from the wrong direction. Your component renderers are using some data to determine which icon to render. So instead of checking which icon has been rendered, you want to sort the grid based on the data that is used determine the rendered icon. Checking the cell's rendered content would also not work for large grids, as the component only renders the rows that are currently visible in the viewport, while sorting should take into account all the rows.
There is an example in the documentation that demonstrates how to set a sort comparator on a column that uses a custom renderer (second example in the linked section): https://vaadin.com/docs/latest/ds/components/grid/#sorting.
Example code from the linked example: