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

Preserve Grid State on Ajax datasource grid

0 Answers 67 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Paul Sieloff
Top achievements
Rank 1
Paul Sieloff asked on 20 Nov 2012, 06:11 PM
Below is my grid.  I set my filter and ordering, click the Details, click back to the Index view and the filter and ordering are lost.  

<h2>Load Summary</h2>
@(Html.Kendo().Grid<MyProject.Models.Invoice>()
    .Name("grid")
    .HtmlAttributes(new { style = "width: 100%" } )
    .Columns(columns => 
        {
            columns.Template(@<text>@Html.ActionLink("Details", "Invoice", "Details", new { id = @item.InvoiceID })</text>)
                .ClientTemplate("<a href='/Invoice/Details/#= InvoiceID#'>Details</a>").Width("5%");
            columns.Bound(p => p.InvoiceNumber).Width("5%").Title("Load No.");
            columns.Bound(p => p.BookDate).Format("{0:d}").Width("5%");
        })
    .DataSource(datasource => datasource
        .Ajax()
        .Read(read => read.Action("GetLoads", "Invoice"))
        .Model(m => m.Id(model => model.InvoiceID))
        )
    .Pageable()
    .Sortable()
    .Filterable()
    .Selectable(selectable => selectable
        .Mode(GridSelectionMode.Single))
)

Here are my controller actions:
        public ActionResult Index()
        {
            IEnumerable<Invoice> invoices = _db.Invoices.Where(p => p.SalesmanID == _salesmanId);
            return View(invoices.ToList());
        }


        //
        // GET: /Invoice/Details/5


        public ActionResult Details(int id = 0)
        {
            Invoice invoice = _db.Invoices.Find(id);
            if (invoice == null)
            {
                return HttpNotFound();
            }
            _routeValues = this.GridRouteValues();
            InvoiceViewModel invoiceViewModel = Mapper.Map<Invoice, InvoiceViewModel>(invoice);
            return View(invoiceViewModel);
        }


        [HttpPost]
        public ActionResult Details(string btnSubmit)
        {
            
            return RedirectToAction("Index", _routeValues);
        }


How can I code this to keep my Filtering and Ordering on my grid?
Thanks

No answers yet. Maybe you can help?

Tags
Grid
Asked by
Paul Sieloff
Top achievements
Rank 1
Share this question
or