Announcement

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

    Set value of a custom FormItem used as a filter editor property

    Hello,

    I would like to create a custom FormItem to use it as a filter editor property. This FormItem is supposed to be a TextItem with a COMBO_BOX PickerIcon. When a user click on the PickerIcon, it shows a TreeGrid just as if it was a SelectItem with a TreeGrid inside of it.
    The problem is when I select a node in the TreeGrid, I would like to update the value of the TextItem, but it does not seem to work. Here is my code :

    Code:
    public class TreeItem extends TextItem implements FormItemClickHandler, SelectionChangedHandler
    {
        private TreeGrid   treeGrid;
        private PickerIcon icon;
    
        public TreeItem()
        {
            TreeGridField field1 = new TreeGridField("name");
    
            TreeNode node1 = new TreeNode();
            node1.setAttribute("name", "name1");
            TreeNode node2 = new TreeNode();
            node2.setAttribute("name", "name2");
    
            Tree tree = new Tree();
            tree.setRoot(new TreeNode());
            tree.setModelType(TreeModelType.PARENT);
            tree.add(node1, tree.getRoot());
            tree.add(node2, node1);
    
            treeGrid = new TreeGrid();
            treeGrid.setFields(field1);
            treeGrid.setData(tree);
            treeGrid.setSelectionAppearance(SelectionAppearance.CHECKBOX);
            treeGrid.setShowSelectedStyle(false);
            treeGrid.setShowPartialSelection(true);
            treeGrid.setWidth100();
            treeGrid.setShowHeader(false);
            treeGrid.setPosition(Positioning.ABSOLUTE);
            treeGrid.addSelectionChangedHandler(this);
            treeGrid.hide();
    
            icon = new PickerIcon(PickerIcon.COMBO_BOX);
            icon.addFormItemClickHandler(this);
    
            setIcons(icon);
        }
    
        @Override
        public void onFormItemClick(FormItemIconClickEvent event)
        {
            if (treeGrid.isVisible())
            {
                treeGrid.hide();
            }
            else
            {
                treeGrid.setLeft(event.getItem().getPageLeft());
                treeGrid.setTop(event.getItem().getPageTop() + event.getItem().getHeight());
                treeGrid.setWidth(event.getItem().getWidth());
                treeGrid.show();
            }
        }
    
        @Override
        public void onSelectionChanged(SelectionEvent event)
        {
            if (event.getSelection().length > 0)
            {
                StringBuilder builder = new StringBuilder();
                builder.append(event.getSelection()[0].getAttribute("name"));
                for (int i = 1; i < event.getSelection().length; i++)
                {
                    builder.append(", ");
                    builder.append(event.getSelection()[i].getAttribute("name"));
                }
                setValue(builder.toString());
            }
        }
    }
    The line "setValue(builder.toString());" does not work when I use my TreeItem as a filter editor property for a ListGrid whereas it works well when I use it as a field in a DynamicForm.
    Thank you.

    #2
    Management of the criteria in the filter editor is very specialized, and won't just pick up a change to your form item's value. Instead, to apply new criteria to the filter editor, you'll need to use a call getFilterEditorCriteria(), modify the criteria, then re-apply it via setFilterEditorCriteria().

    Comment

    Working...
    X