We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Restore filter settings on page load

Hello,
I would like to restore the saved filters of the grid during the last visit on the page. I would like to know how to save and restore the settings on server side.
Thank you very much for your help,
Mirko


3 Replies

PS Prabu Sarvesan Syncfusion Team November 19, 2013 12:05 PM UTC

Hi Mirko,

Thanks for your interest in Syncfusion product.

We would like to let you know that your requirement “Restore filter settings on page load” has been achieved on the server side. To achieve your requirement use Filter Descriptor values to restore filter settings on page load. To maintain paging, Sorting and other grid functionality use session concepts. The code snippets is shown below,

Code Snippet:

[CS]

public class HomeController : Controller

    {

   public ActionResult Index()

        {

            if (Session["Args"] != null)

            {

                List<AutoFormatting> data1 = new List<AutoFormatting>();

                var arg = (List<FilterDescriptor>)Session["Args"];

                for (int i = 0; i < arg.Count; i++)

                {

                    var col = arg[i].ColumnName;

                    var val = arg[i].Value.ToString();

List<AutoFormatting> data =                                  (List<AutoFormatting>)AutoformatRepository.GetData();

                    foreach(var dat in data)

                    {

 if ( dat.Currency.ToString()==val.ToString() || dat.Dates.ToString() ==  val.ToString() || dat.Number.ToString() == val.ToString() || dat.Telephone.ToString() == val.ToString())

                        {

                            data1.Add(dat);

                        }

                    }     

                }

                Session["Data"] = data1;

                return View(data1);

            }

            var data2 = AutoformatRepository.GetData();

            return View(data2);

        } 

 

        [AcceptVerbs(HttpVerbs.Post)]

        public ActionResult Index(PagingParams args)

        {

            if (args.FilterDescriptors.Count != 0)

            {

                Session["Args"] = args.FilterDescriptors;

            }

            if (Session["Data"] != null)

            {

                List<AutoFormatting> data1 = (List<AutoFormatting>)Session["Data"];

                Session["Data"] = data1;

                return data1.GridActions<AutoFormatting>();

            }

            IEnumerable data = AutoformatRepository.GetData();

            return data.GridActions<AutoFormatting>();

 

        }

}

 

For your convenience we have created a sample and the same can be download from the below attachment.

Please let us know if you need any further assistance.

Regards,

Prabhu Sarvesan



SampleGrid_e334ec1d.zip


AP Aditi Patre March 1, 2018 02:06 PM UTC

Can we retain the filter settings on page size settings change ? (Dropdown displays the page-size).


IR Isuriya Rajan Syncfusion Team March 5, 2018 04:26 PM UTC

Hi Aditi, 
 
Thanks for contacting Syncfusion support, 
 
Please refer the below KB for your requirement. 
 
 
Please get back to us if you need any other assistance. 
 
Regards, 
Isuriya R 


Loader.
Live Chat Icon For mobile
Up arrow icon