0
votes

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.

1
Have a look at Hilite, you can set an array of conditionnal hilites for your ListGrid and evry time a record fill the conditions it will have the css of the hilite applied. - Alain BUFERNE
I'll try this out along with @gpapaz tip and get back to all. - Shrinivas

1 Answers

0
votes

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.