joeharrison714 / MVCGrid.Net

http://mvcgrid.net
MIT License
75 stars 56 forks source link

Reset Filters? #112

Closed kitchenbin closed 6 years ago

kitchenbin commented 7 years ago

Hello. Thank you for developing this grid - it's the easiest to use and so powerful. I'm wondering if there's an easy way to clear all filters please? I could go programatically field by field on the UI and clear each control, but I'm thinking if there's a .clear or .reset command already on the grid which will automatically do this for me? Thanks.

zairja commented 6 years ago

I implemented the following on the page where I needed to do the same. It relies on jQuery ($) but could be done in a few more lines of code with pure JS. There is an option in the client-side API (.setFilters), but it is buggy at the moment.

<button id="btnClearInputs" type="button" onclick="ClearInputs()" 
     data-mvcgrid-apply-filter="click">Reset Filter(s) and Reload Grid</button>

<--- further down --->

<script>
function ClearInputs() {
            $(':input').val('');  // one could also do a selector query based on class or other attribute
        }
</script>
kitchenbin commented 6 years ago

Perfect! Exactly what I was looking for. Thank you Zairja.