SmartGWT LiveGrid 无法以编程方式将样式应用于网格记录

发布于 2025-01-02 16:24:28 字数 618 浏览 2 评论 0 原文

我正在使用 SmartGWT 2.5,特别是由 RESTDataSource 支持的 ListGrid。 服务器集成是通过servlet的方式实现的,我只需要实现fetchData()。数据是在服务器端填充的 List>,转换为 JSON 并在 DSResponse 中发送。数据源支持的实时网格通过 grid.fetchData() 以编程方式触发服务器获取。

要求: 我希望根据我从服务器发送的记录属性之一的值设置记录基本样式(或自定义样式)。 为了做到这一点,我尝试了 DataArrivedHandler,在其中迭代可用行,使用行号从网格获取 ListGridRecord,并使用 gridRecord.set_baseStyle(String stylename) 或 gridRecord.setCustomStyle(String stylename) 来尝试并为该记录应用灰色的 CSS。之后,我调用 grid.markForRedraw(),但没有效果。 CSS 不会被应用。

我必须提到,我已经使用相同的 css 非常成功地将普通 listGrid(无数据源)上的行变灰。

问题: 我的策略正确吗? 是否有另一种方法可以根据属性值将样式应用于记录。

I am using SmartGWT 2.5, specifically a ListGrid backed by a RESTDataSource.
The Server integration is achieved by way of a servlet, and I only need to implement fetchData(). The data is a List<Map<String, Object>> populated on the server side, converted into JSON and sent in the DSResponse. The Live grid backed by the datasource triggers a server fetch programmatically by way of grid.fetchData().

Requirement:
I wish to set a record base style (or custom style) based on the value of one of the record's attributes, which I send over from the server.
In order to do this, I have tried a DataArrivedHandler, where I iterate over the available rows, get the ListGridRecord from the grid using the row number, and use gridRecord.set_baseStyle(String stylename) or gridRecord.setCustomStyle(String stylename) to try and apply a greyed out css for that record. After this, I call grid.markForRedraw(), however to no effect. The CSS does not get applied.

I must mention that I have used the same css to grey out rows on a normal listGrid (no dataSource) very successfully.

Questions:
Is my strategy the right one?
Is there an alternative method to apply a style to a record based on an attribute value.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一直在等你来 2025-01-09 16:24:28

您的策略是正确的,我已经在我的代码中成功实现了您所需的功能。确保您正确获取记录并且其中存在测试属性。我建议使用 JSON.encode(record.getJsObj()) 来查看您的记录实际填充的内容。无需显式调用 markForRedraw(),因为在 DataArrivedEvent 触发后,ListGrid 将重绘其视图。如果您需要更多帮助,请发布一个小代码片段。另外,正如阿兰的评论所建议的,亮点可能是另一个不错的选择。

Your strategy is correct and I have successfully achieved your required functionality in code of mine. Make sure you are correctly getting the record and that the test attribute is present in it. I suggest a JSON.encode(record.getJsObj()) to see what your record actually is filled with. No need for markForRedraw() explicit call, as after the DataArrivedEvent has fired the ListGrid will redraw its view. Post a small code snippet if you need more help. Also as suggested from the comment from Alain, highlights might be another good option to look at.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文