This is a migrated thread and some comments may be shown as answers.

Grid Filter via treeview?

5 Answers 352 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 28 Apr 2017, 04:39 PM

Can I change the filter to be a treeview if I have a hierarchical data source for it?  I've been trying but not seeing any data.If I view the source I can see the treeview and all the data but the filter doesn't show the data on the screen.

 

My column is defined like this:

field: "country",
                    headerTemplate: '<span title="' + myTranslator.translate("Country", "Country") + '" data-toggle="tooltip" data-placement="right">' + myTranslator.translate("Country", "Country") + '</span>',
                    filterable: {
                        ui: createCountrySelect,
                        extra: false,
                        operators: {
                            string: {
                                contains: myTranslator.translate("Contains", "Contains")
                            }
                        }
                    },
                    groupHeaderTemplate: kendo.template($("#group-row-template").html())

 

And the createCountrySelect:

 

function createCountrySelect(element) {
    element.removeAttr("data-bind");
 
    var ds = new kendo.data.HierarchicalDataSource({
        data: vm.unflattedGeographicUnits,
        schema: {
            model: {
                id: "recordID",
                hasChildren: function (node) {
                    return (node.items && node.items.length > 0);
                },
                children: {
                    schema: {
                        data: "items",
                        model: {
                            id: "recordID",
                            hasChildren: function (node) {
                                return (node.items && node.items.length > 0);
                            }
                        }
                    }
                }
            }
        }
    });
 
    element.kendoTreeView({
        dataSource: ds,
        dataTextField: "name",
        change: function (e) {
            var filter = { logic: "or", filters: [] };
            var values = this.value();
            $.each(values, function (i, v) {
                filter.filters.push({ field: "geographicUnits", operator: "contains", value: v });
            });
            vm.countryDataSource.filter(filter);
        }
    });
}

 

5 Answers, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 02 May 2017, 08:38 AM

Hello,

The same approach for filtering is used in our Use MultiSelect for Column Filtering how-to example. As far as I understand the same idea is used here. I would suggest to inspect the filters applied to the grid datasource and check whether the logic, operator, fields value are correct. More information about the filters collection you can find in the filter.filters article. 

Regards,
Boyan Dimitrov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Jason
Top achievements
Rank 1
answered on 05 May 2017, 01:48 PM
I would have expected the treeview to work the same way as well so I used the multiselect filtering as my starting point.  It looks like the treeview is being built but nothing displays except a text box.  I modified that example and changed it to treeview and was able to replicate my issue.  Please let me know what I am doing wrong.  http://dojo.telerik.com/aMoKi
0
Jason
Top achievements
Rank 1
answered on 05 May 2017, 01:58 PM
And an even simpler example with a basic hierarchichal datasource:  http://dojo.telerik.com/IXOjO
0
Boyan Dimitrov
Telerik team
answered on 09 May 2017, 03:04 PM

Hello Jason,

In general the problem here is that the Kendo UI TreeView should be initialized from div element, but the default element in the filter menu is an input element. The TreeView can not be initialized from an input element. Even if you add a div element and remove the input the UI might break since it is designed to have an input widget. My suggestion is to implement a separate filter from with a Kendo UI TreeView and a button outside the grid. In order to apply filter expression to the grid you can use the Kendo UI DataSource filter method. 

Regards,
Boyan Dimitrov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Josiah
Top achievements
Rank 1
Veteran
answered on 24 Mar 2021, 05:11 PM
 an example of an outside Treeview for filtering would be very helpful. I have done this previously, but synchronizing that filter with all of the other filters was proving difficult. Plus,  if you're persisting grid status, there's a huge headache of trying to keep the Treeview synchronized.  so an example like you talked about working with grid persistence what I think be a huge help to the community. Thank you
Tags
Grid
Asked by
Jason
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Jason
Top achievements
Rank 1
Josiah
Top achievements
Rank 1
Veteran
Share this question
or