Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    multiSelectItem with groups

    Hi all,

    I created a grouped Multi SelectItem which worked and looked fine. However, I want a user to be able to select all /deselect all also in collapsed groups once he/she clicks on the SelectItem grid's header checkbox.

    My idea is to expand all the groups once the user clicks on the header checkbox and depending the records' selection state I fire either a deselectAll or selectAllRecords on all groups' records.
    However I can’t access the select Item’s groups. In the code below I experimented with the picklistProperties ListGrid (since it's the same ListGrid I used to set the SelectItem's groups) in the HeaderClickHandler with getGroupTree().openAll () but it is always null.

    Am I missing out something? Please look at my code and provide me with clues on how I can achieve “select all/deselect all" on all records (including collapsed groups) of a grouped multi SelectItem

    Thanks

    Code:
    private static FormItem createGroupedSelectItem() {
            final SelectItem item = new SelectItem(); // field left out
    
            item.setPickListFields(new ListGridField("name"), new ListGridField("type"));
            item.setPickListWidth(400);
    
            item.setAllowEmptyValue(false);
            item.setMultiple(true);
            item.setDisplayField("name");
            final ListGrid picklistProperties = new ListGrid() {
                {
                    setGroupByField("type");
                    setShowFilterEditor(true);
                    setBackgroundColor("white");
                    setSort(new SortSpecifier[] { new SortSpecifier("type", SortDirection.ASCENDING),
                            new SortSpecifier("name", SortDirection.ASCENDING) });
                }
            };
    
            picklistProperties.addHeaderClickHandler(new HeaderClickHandler() {
    
                @Override
                public void onHeaderClick(HeaderClickEvent event) {
    
                    if (event.getFieldNum() == 0) {
                        item.getClientPickListData();
                        if (picklistProperties.getSelectedRecord() != null) {
                            picklistProperties.getGroupTree().openAll();
                            picklistProperties.deselectAllRecords();
                        }
    
                    }
    
                }
            });
    
            item.setPickListProperties(picklistProperties);
            return item;
        }

    #2
    In general when adding event handlers via AutoChild APIs, you can't interact with the "properties" object you passed in as though it were the same as the final widget. It's just a configuration for the final widget (and often, it's used to create multiple widgets, so it's not even 1-1).

    What you're attempting here is some fairly deep AutoChild hackery, and it's borderline whether this is valid customization vs best handled by creating a widget that has it's own PickList. However, one way to find your way to the actual PickList in this case would be EventHandler.getTarget().

    As far as affecting the selection, use FormItem.setValue() to update it, not direct changes to the PickList selection (which would be analogous to scribbling on the internal database of an application, and just hoping it works).

    Comment

    Working...
    X