I was wondering if there's a way to gray out items in the drop-down box from a SelectItem. Specifically for one using a option ListGrid. Thanks!
Announcement
Collapse
No announcement yet.
X
-
There's no simple built in flag to disable selection of certain items from the valueMap, no.
You could achieve this via some customization. Explicit records can be provided to the SelectItem via an optionDataSource [could be clientOnly:true]. You could set the enabled attribute to false on certain of these records to suppress selection and show disabled styling. You could perform further customizations [changing styling, setting the recordEnabledProperty, etc] via a call to 'setPickListProperties()' on your selectItem.
-
I worked through this and it's easier than it sounds. Hope this helps others....
To create a Client side DataSource:
Code:// Create DataSource with two fields, 'value' and 'display'; I use string IDs but integers will work final DataSource dataSource = new DataSource(); dataSource.setClientOnly(true); dataSource.setFields( new DataSourceField("value", FieldType.TEXT), new DataSourceField("display", FieldType.TEXT) ); // Add some value/display pairs; I convert the id to a string because it's really a Long for(BlahObject dto : dtos) { ListGridRecord record = new ListGridRecord(); record.setAttribute("value", dto.id.toString()); record.setAttribute("display", dto.description != null ? dto.description.trim() : ""); record.setEnabled(dto.active); dataSource.addData(record); } return dataSource;
To use the DataSource in a SelectItem:
Code:SelectItem selectItem = new SelectItem("selectItem", "Select Item"); selectItem.setOptionDataSource(dataSource); selectItem.setValueField("value"); selectItem.setDisplayField("display");
Comment
Comment