Announcement

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

    TreeGrid : filterData() but keeping the children elements.

    Hi everyone,

    I have a TreeGrid with a DataSource, and use the native filterData() function to filter the content being displayed to match a given keyword. Parent folders are kept, and children ones are (obvisouly) not retrieved. But my need is to keep the children folders and leaves displayed, to allow the user to explore the content below the folders which match his keyword. (Like a setKeepParentsOnFilter() but setKeepChildrenOnFilter().)

    So in the callback of filterData(), my idea is to reload/refresh the content of the folder which match the keyword, but how should I do that ?...
    Any help will be much appreciated ! Thanks.
    Elie

    (gwt.version : 2.8.0)

    Code:
    globalTreeGrid.filterData(new TreeFilter(
            fieldToDisplay,
            selectionType,
            flatten,
            filterTextItemId.getValueAsString(),
            filterTextItemLabel.getValueAsString(),
            allowVirtualFolders), new DSCallback() {
        @Override
        public void execute(DSResponse response, Object rawData, DSRequest request) {
    
            for (Record record : response.getData()){
                boolean isFolder = record.getAttributeAsBoolean("isFolder");
                String shortdesc = record.getAttributeAsString("shortdesc");
                String filterTextItemLabelValue = filterTextItemLabel.getValueAsString();
                if (filterTextItemLabel != null && isFolder && shortdesc != null && shortdesc.contains(filterTextItemLabelValue)){
                    TreeNode wantedNode = globalTreeGrid.getData().findById(record.getAttributeAsString("id"));
                    boolean isLoaded = globalTreeGrid.getData().isLoaded(wantedNode);
    
                    globalTreeGrid.refreshData();//ineffective
                    globalTreeGrid.openFolder(wantedNode);
                }
            }
            globalTreeGrid.fireEvent(new ItemsCounterEvent(response.getTotalRows()));
        }
    });

    #2
    refreshData() refreshes data with the same criteria - same filtering will occur.

    openFolder() would do nothing because the folder is open already. Even reloadChildren() won't really work because again, the same criteria are applied.

    Basically, you need to:

    1. have your server return children even when criteria are being applied

    2. disable client filtering (resultTreeProperties.useClientFiltering:false) because otherwise the client-side filtering will (correctly) drop the child nodes anyway

    Comment

    Working...
    X