Filter grid using parent controls, save filters to session storage
Saving grid filters to the sessionStorage, you can change the filters and refresh the page, the filters will remain the same.
Instead of sessionStorage you could use localStorage or use ajax to save the filters on the server in a database.
GridSaveFilters/Index.cshtml
<div class="bar" id="bar1"> @Html.Awe().TextBox("txtPerson").Placeholder("search for person ...").Value("Le").CssClass("searchtxt") @Html.Awe().TextBox("txtFood").Placeholder("search for food ...").CssClass("searchtxt") @Html.Awe().DropdownList(new DropdownListOpt{ Name = "selCountry", Url = Url.Action("GetCountries", "Data")}) <button type="button" class="awe-btn" id="btnClearFlt"> Clear filters </button> </div>
<script> $(function () { var key = "Grid1-Flt"; var cont = $('#bar1');
// load filters var strval = sessionStorage[key]; var fltData = strval ? JSON.parse(strval) : {};
cont.find('input[name]').each(function () { var el = $(this); var name = el.attr('name'); el.val(fltData[name]).trigger('change'); });
// save filter cont.on('change', function (e) { var el = $(e.target); var name = el.attr('name'); if (!name) return; fltData[name] = el.val(); sessionStorage[key] = JSON.stringify(fltData); });