Filter is only applied to the 1st hierarchy of the TreeView

6 posts, 1 answers
  1. Answer
    Alberto
    Alberto avatar
    4 posts
    Member since:
    Nov 2012

    Posted 09 Jan 2013 Link to this post

    Hi all!

    I'm using the feature described here http://demos.kendoui.com/web/treeview/api.html to filter treeview items by text. 

    I already have all nodes loaded (they are not all expanded), but when I apply the filter using the code above, it does not work.

    treeview.dataSource.filter({
    field: "text",
    operator: "contains",
    value: filterText
    });

    Example 

    • Item aa
    • Item bb
      • Item xx
      • Item yy

    if search text is "xx", no items are displayed. Instead I would like to have the following result:

    • Item bb
      • Item xx
    But if your search text is "aa", "bb" or some string similar to root item texts ... the nodes are displayed

    Does anyone knows how to make the filter applying for all nodes?

    BTW! I'm using MVC and the last build of Kendo

    Thanks!
  2. Alex Gyoshev
    Admin
    Alex Gyoshev avatar
    2500 posts

    Posted 10 Jan 2013 Link to this post

    Hello Alberto,

    See the following StackOverflow thread for a solution.

    Regards,
    Alex Gyoshev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Otto Neff
    Otto Neff avatar
    36 posts
    Member since:
    Jul 2011

    Posted 12 Nov 2014 Link to this post

    If you need more than just "findByText" try this

    that.nodeFilter = { logic: "or", filters: [] };
    that.nodeFilter.filters.push({ field: "hidden", operator: "eq", value: false });
    tree.element.find(".k-in").each(function () {
        var dItem = tree.dataItem($(this).closest("li"));
        dItem.hidden = false;
        if (dItem["VALUE"].toLowerCase().indexOf(searchTerm) != -1 ||
            dItem["TEXT"].toLowerCase().indexOf(searchTerm) != -1) {
            that.nodeFilter.filters.push({ field: "VALUE", operator: "eq", value: dItem["VALUE"] })
            while (dItem.parentNode()) {
                dItem = dItem.parentNode();
                dItem.hidden = false;
                that.nodeFilter.filters.push({ field: "VALUE", operator: "eq", value: dItem["VALUE"] })
            }
        } else {
            dItem.hidden = true;
        }
    });
    tree.dataSource.filter(that.nodeFilter);
    tree.element.find(".k-in").each(function () {
        var node = $(this).closest("li");
        var dataItem = tree.dataItem(node);
        if (dataItem.hidden) {
            tree.remove(node);
        }
    });
  5. Marian
    Marian  avatar
    3 posts
    Member since:
    Apr 2015

    Posted 13 Nov 2015 in reply to Alex Gyoshev Link to this post

    Hi, How can I provide all levels filtering when I'm using server-side operations?
  6. Marian
    Marian  avatar
    3 posts
    Member since:
    Apr 2015

    Posted 13 Nov 2015 in reply to Marian Link to this post

    I can see that data.ToDataSourceResult(request); finds correct record but it does not get displayed in the treeview
  7. Alex Gyoshev
    Admin
    Alex Gyoshev avatar
    2500 posts

    Posted 17 Nov 2015 Link to this post

    Hello Marian,

    I am afraid that this feature is not supported by the TreeView widget at this time. Please open separate threads when the question deviates from the original post.

    Regards,
    Alex Gyoshev
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for ASP.NET MVC is VS 2017 Ready