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

Clear the filter on a column of a grid .

14 Answers 1965 Views
Grid
This is a migrated thread and some comments may be shown as answers.
chatrapathi
Top achievements
Rank 1
chatrapathi asked on 27 Mar 2014, 10:04 PM
Hi ,

I have a filters on one or more columns of the grid . And I want to achive to  clear a filter on one of the column of the grid ;ie Instead of manually clicking the clear button of the column filter .


I have gone through slice which will reset all the filters in a grid and same way 


the click event of button to reset all the filters of grids in the page .($("form.k-filter-menu button[type='reset']").trigger("click");) which I am not interested -in.

Thanks,
Chatrapathi

14 Answers, 1 is accepted

Sort by
0
Kiril Nikolov
Telerik team
answered on 28 Mar 2014, 04:06 PM
Hello Chatrapathi,

You can clear the filters per column using the dataSource filter(), method where you can check the current filter and remove them. The only problems might be that the filter icon will stay highlighted, so you will need to clear it manually.

Please check the following example, that I created and let me know if you have any questions:

http://jsbin.com/cisofivo/1/edit

Regards,
Kiril Nikolov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Chatra
Top achievements
Rank 1
answered on 11 Apr 2014, 01:58 PM
Hi Kiril,

That helped thank you :)

Thanks
Chatrapathi
0
Kiril Nikolov
Telerik team
answered on 14 Apr 2014, 07:53 AM
Hello Chatra,

I am really happy to hear that the provided solution helped.

In case you have any further questions, please do not hesitate to contact us.

Regards,
Kiril Nikolov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Tim
Top achievements
Rank 1
answered on 14 Apr 2014, 11:40 AM
Hi Kiril,

I saw this post when searching the forum.
I'm also struggling  with clearing the filters. I don't unstand how I can clear the filter of just that one column (for example: areaOfStudy).
Can you post an example of this please?

Kind regards,

Tim
0
Kiril Nikolov
Telerik team
answered on 14 Apr 2014, 12:08 PM
Hello Tim,

You can clear the filters for a particular column, by putting its field name in the filter object. Please check the following example:

http://jsbin.com/dosos/1/edit

Regards,
Kiril Nikolov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Tim
Top achievements
Rank 1
answered on 14 Apr 2014, 12:40 PM
Hello Kiril,

Thanks for the provided solution.
It's much clearer for me now.

Kind regards,

Tim
0
Chatra
Top achievements
Rank 1
answered on 14 Apr 2014, 02:17 PM
Hi Kiril,

I have one more question from Multi select & Templates related . And here is the link for it http://www.telerik.com/forums/kendo-ui-multiselect-on-grid-toolbar-in-a-tab-strip-of-popup-editor#XkrgeLT6A0KaqtMGLaLbsA.

And demo for it is at http://jsbin.com/kibidipo/10/edit

It would be great if you could help me In that. Let me know if you require more Info on it.

Thanks in Advance ,

Thanks
Chatrapathi Chennam
0
Tim
Top achievements
Rank 1
answered on 15 Apr 2014, 06:58 AM
Hello Chatra,

The provided link to the item on the forum isn't working.
Could you please post the correct link again?

Kind regards,

Tim
0
Kiril Nikolov
Telerik team
answered on 15 Apr 2014, 07:34 AM
Hello Guys,

As the question moves from the original topic of the conversation I would suggest you to open a different support thread about the Multi Select issues that you are having, so the people responsible for this widget can take a look.

Thank you in advance for your understanding and cooperation.

Regards,
Kiril Nikolov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Tim
Top achievements
Rank 1
answered on 25 Apr 2014, 06:57 AM
Hi Kiril,

I tried to implement the provided sollution and the filter for the column is indeed cleared but all the other filters are also removed by this.
What i'm looking for only cleares the filter for that one column and keeps the other filters.
Do you have any other suggestions?

Kind Regards,

Tim
0
Kiril Nikolov
Telerik team
answered on 25 Apr 2014, 01:27 PM
Hi Tim,

The filter() method of the dataSource can take an array of filters, so what you can do is get the current filter configuration, remove the unneeded filters and then apply the rest of the filters back to the dataSource, this way you will remove only the unneeded one. As in this example:

http://jsbin.com/divug/1/edit

Regards,
Kiril Nikolov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Tim
Top achievements
Rank 1
answered on 28 Apr 2014, 12:56 PM
Hello Kiril,

Thank you for the reply.
When trying out your example i was able to clear the filter i knew in what position it was. But when other filters where applied problems rose.
For example:

Filter: (Apple or Banana) AND ((Fruit  or Vegetable) AND (Banana AND Food ) => I would like to remove the the deepest Banana because i would only get the banana as a result

In the code example below i try to do this only allows me to remove the first parameter and not the parameter i'm looking for

function RemoveCategoryFilter(filter) {
    var filterFound = 0
    if (filter.filters) {
        for (var i = 0; i < filter.filters.length; i++) {
            if (filter.filters[i].field == "Name") {
                var newFilter = filter.filters.splice(1, 1);
                filterFound = 1
                return newFilter;
            }
            filterFound = SearchCategoryFilter(filter.filters[i], filterFound);
        }
    }
    if (filterFound == 1) {
        filter.filters.splice(0, 1);
        return filter;
    }
    else {
        return filter;
    }
 
}
 
function SearchCategoryFilter(filter, filterFound) {
    if (filter.filters) {
        for (var i = 0; i < filter.filters.length; i++) {
            if (filter.filters[i].field == "Name") {
                filterFound = 1
                return filterFound;
            }
            filterFound = SearchCategoryFilter(filter.filters[i], filterFound);
        }
    }
    return filterFound;
}

Kind Regards,

Tim
0
Kiril Nikolov
Telerik team
answered on 29 Apr 2014, 11:08 AM
Hello Tim,

I am really sorry but I cannot understand what exactly you are trying to do. Could you please edit the example that I provided so it can show the exact problem that you are having?

Thank you very much for the cooperation. 

Regards,
Kiril Nikolov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Graham
Top achievements
Rank 2
Iron
Iron
answered on 23 Apr 2018, 11:06 AM

Easy way (no iterating and no splicing):

    var grid = $('#myGrid').data("kendoGrid");

    grid.dataSource.filter({
        field: "myColumn",
        operator: "neq",
        value: "zzz"
    });

Tags
Grid
Asked by
chatrapathi
Top achievements
Rank 1
Answers by
Kiril Nikolov
Telerik team
Chatra
Top achievements
Rank 1
Tim
Top achievements
Rank 1
Graham
Top achievements
Rank 2
Iron
Iron
Share this question
or