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

[Solved] Filter lost when change page

2 Answers 130 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Steve
Top achievements
Rank 1
Steve asked on 11 Sep 2010, 01:04 AM
Hi,

    I have MVC Grid version 2010.2.825.  When I click on Edit button in the grid, I transfer to another page and when I return to my grid, the filter is lost.  Do you know how I can keep the filter in grid between page transfers?

Thank you
Steve

2 Answers, 1 is accepted

Sort by
0
Daniel
Top achievements
Rank 1
answered on 14 Sep 2010, 03:20 AM
If you use the Grid Edit mode you don't tranfer to another page.

If you use Server Editing the page "reload" after Edit and If you use Ajax Binding only the grid is reload.

To keep the filter try to use the method GridRouteValues().

The example say (in Server Editing):

//GridRouteValues() is an extension method which returns the
//route values defining the grid state - current page, sort expression, filter etc.
RouteValueDictionary routeValues = this.GridRouteValues();

I recommend you view the examples.

Daniel.
0
Steve
Top achievements
Rank 1
answered on 21 Sep 2010, 03:03 AM
Thank you for your help.  I tried GridRouteValues but this dictionnary is empty. 
Here is the line I have in my View

.Filterable(f => f.Filters(config => config.Add(col => col.Actif).IsEqualTo(true)))

Do you know how I can change it to works in callback?

Here is the code in my Edit Post Action
[HttpPost]
public ActionResult Edit(Guid id, FormCollection collection)
{
    try
    {
        var viewData = this.InitializeMemberViewData();
        viewData.Membre = this._container.GetMemberById(id);
        if (!IsMembreUnique(collection["Membre.Nom"], collection["Membre.Prenom"], int.Parse(collection["Membre.fk_Unite_UniteAdm"] ?? "0"), id))
        {
            this.ModelState.AddModelError("MembreDouble", "Ce membre existe déjà");
            return View(viewData);
        }
        var valueProviders = collection.ToValueProvider();
        bool updateModelResult = TryUpdateModel(viewData, null, null, new[] { "Membre.pk_MembreId" }, valueProviders);
        if (!updateModelResult)
        {
            return View(viewData);
        }
        else
        {
            this._container.SaveChanges();
            RouteValueDictionary routeValues = this.GridRouteValues();
            return RedirectToAction("Index", routeValues);
        }
    }
    catch
    {
        return View();
    }
}


Thank you
Tags
Grid
Asked by
Steve
Top achievements
Rank 1
Answers by
Daniel
Top achievements
Rank 1
Steve
Top achievements
Rank 1
Share this question
or