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

[Solved] Grid Losing Search Criteria

1 Answer 33 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.
Jako
Top achievements
Rank 1
Jako asked on 23 Apr 2013, 02:17 PM
hi there

I have a grid with an option to search for a company. it is working great, but when I page the grid, it loses the criteria and resets to a full list again. Is there a way to keep the criteria of the user?
Controller
[HttpGet]
public ActionResult CompanyList()
{           
    var model = _saleService.GetCompanyList();
 
    return View(model);
}
 
[HttpPost]
public ActionResult CompanyList(FormCollection formCollection)
{
    string companyName = formCollection["uxSearch"].ToString();
    var model = _saleService.GetCompanyList();
 
    if (String.IsNullOrEmpty(companyName))
    {
        ModelState.AddModelError("", "Please enter a company name");               
    }
    else
    {
        model = _saleService.GetCompanyList(companyName);               
    }
 
    return View(model);
}
    
View
@model IList<Company.ViewModels.CompanyList>
@{
    Layout = "~/Views/Shared/_SecureLayout.cshtml";
}
@using (Html.BeginForm())
{   
    @Html.ValidationSummary(true, "Please enter a name before searching.");
    <input type="text" name="uxSearch" />
    <input type="submit" name="uxSearchSubmit" value="search" />
    @(Html.Telerik().Grid(Model)
        .Name("uxCompanyListGrid")
        .Columns(columns =>
            {
                columns.Template(
                        @<text>
                            @(Html.ActionLink("Change", "RequestChange", "Secure", new { companyID = item.companyID })
                        </text>).Width(60);
                columns.Bound(i => i.Name);
                columns.Bound(i => i.CountryOfPublication).Title("Country").Width(100);
            })
        .DataBinding(dataBinding =>
            {
                dataBinding.Server().Select("CompanyList", "Secure");
            })
        .Scrollable
        (s => s.Enabled(true)
                .Height("500px")
        )
        .Sortable(s => s.Enabled(true))
        .Pageable
            (p => p.Enabled(true)
                    .PageSize(30)
            )
        .Filterable(f => f.Enabled(true))
        .Footer(true)
    )
}

1 Answer, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 26 Apr 2013, 12:49 PM
Hi,

You could pass the needed parameters as route values with the Grid and filter the data in the main action e.g.

[HttpGet]
public ActionResult CompanyList(string companyName)
{          
    var model = _saleService.GetCompanyList();
    if (!String.IsNullOrEmpty(companyName)){
        ViewBag.companyName = companyName;
        model = _saleService.GetCompanyList(companyName);
    }
    return View(model);
}
  
[HttpPost]
public ActionResult CompanyList(FormCollection formCollection)
{
    string companyName = formCollection["uxSearch"].ToString();
    var model = _saleService.GetCompanyList();
  
    if (String.IsNullOrEmpty(companyName))
    {
        ModelState.AddModelError("", "Please enter a company name");              
    }
    else
    {
        model = _saleService.GetCompanyList(companyName); 
        ViewBag.companyName = companyName;       
    }
  
    return View(model);
}
.DataBinding(dataBinding =>
            {
                dataBinding.Server().Select("CompanyList", "Secure", new { companyName= ViewBag.companyName});
            })
Regards,
Daniel
the Telerik team
Check out the successor of Telerik MVC Extensions - Kendo UI for ASP.NET MVC - and deem it for new ASP.NET MVC development.
Tags
Grid
Asked by
Jako
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or