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

[Solved] grid losing filters and sortings when using AJAX

1 Answer 61 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Simon Christ
Top achievements
Rank 1
Simon Christ asked on 13 Mar 2013, 01:12 PM

Hi all

I have a problem with an Telerik Grid.
Until I can editing direct in the Grid (with AJAX), i have the following problem:
If i’ll editing all data from a line, i go to a editing window with this command:

columns.Command(commands =>
        {
            commands.Custom("editDetail")
                .ButtonType(type)
                .HtmlAttributes(new { @class = "editDetail" })
                .Text("edit")
                .DataRouteValues(route => route.Add(o => o.GeschaeftID).RouteKey("GeschaeftID"))
                .Ajax(false)
                .Action("Edit", "Geschaeft");
        }).Width(38).Title("");

When i finished with the editing, i get back to the site with the Grid.
And now i‘ve lost all filters and sortings.
If i don’t need the AJAX for edting direct in the Grid i don’t loosing the filter and sortings.
I guess the problem ist by the AJAX.
Do you have an idea, what to do that i don't lose the filters and sortings when i using AJAX?

This is my Code:


@(Html.Telerik().Grid<Model>()
    .Name("Grid")
    .DataKeys(keys => keys.Add(c => c.GeschaeftID))
    .ToolBar(commands => { commands.SubmitChanges(); })
    .DataBinding(dataBinding =>
            dataBinding.Ajax()
                .Select("_Index", "Geschaeft")
                .Update("_SaveBatchEditing", "Geschaeft")
    )
    .Columns(columns =>
    {
        columns.Command(commands =>
        {
            commands.Custom("editDetail")
                .ButtonType(type)
                .HtmlAttributes(new { @class = "editDetail" })
                .Text("edit")
                .DataRouteValues(route => route.Add(o => o.GeschaeftID).RouteKey("GeschaeftID"))
                .Ajax(false)
                .Action("Edit", "Geschaeft");
        }).Width(38).Title("");
        columns.Bound(o => o.xy)
            .ClientTemplate("<#=xy? 'ja' : 'nein' #>")
            .Title("A")
            .HeaderHtmlAttributes(new { title = "xy" })
            .Width(12);
        columns.Bound(o => o.xz)
            .Width(84)
            .Title("xz")
            .ReadOnly()
            .ClientTemplate("<#=xz#>");
        columns.Bound(o => o.xf)
            .Title("xf")
            .Width(250)
            .ReadOnly();
    })
    .DetailView(details => details.ClientTemplate(
        Html.Telerik().Grid<Model>()
        .Name("V")
        .Columns(columns =>
        {
            columns.Bound(o => o.vx)
            .Width(90)
            .Title("vx")
            .ReadOnly();
            columns.Bound(o => o.vz)
            .Title("vz")
            .ReadOnly();
        })
        .DataBinding(dataBinding => dataBinding.Ajax()
                .Select("_DetailViewAjax", "Geschaeft", new { geschaeftID = "<#= GeschaeftID #>" }))
        .ToHtmlString()
    ))
    
    .ClientEvents(events => events
        .OnDataBinding("Grid_onDataBinding")
        .OnError("Grid_onError"))
        .Editable(editing => editing.Mode(GridEditMode.InCell))
     .Scrollable(scrolling => scrolling.Enabled(false).Height("auto"))           
     .TableHtmlAttributes(new { style = "table-layout = fixed" })
        .Resizable(resizing => resizing.Columns(true))
        .Sortable()
        .Filterable()
        .Groupable()          
        .Pageable(paging =>
            paging
                .PageSize(ViewBag.PageSize)
                .Style(GridPagerStyles.Status)
                .Position(GridPagerPosition.Bottom)
        )
    )

1 Answer, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 18 Mar 2013, 12:56 PM
Hello Simon,

When you are not using Ajax the whole page is reloaded and thus the Grid is completely reloaded and thus the state of the Grid is completely lost.

If you are interested how you can persist the state of the Grid in a cookie I would suggest you to check this code library article.

Regards,
Petur Subev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Simon Christ
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Share this question
or