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

[Solved] Loosing formats when paging through the grid (Ajax Binding)

5 Answers 138 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.
Ben
Top achievements
Rank 1
Ben asked on 04 Apr 2011, 01:41 PM
Hi there,

i`ve got a problem with the Ajax Binding of the ASP.NET MVC Grid. I retrieve data from a WebService as a List<T> and bind this to the Grid. When the View is loaded, the Grid looks fine and the first 10 Rows are filled correctly, but when the User pages through the grid the data looses their format. 

List<DocumentItemDto> data = ArticleHistoryProvider.GetDocumentItems(clienReportingRequest);
return View("SearchResult", data);

Here`s the Razor of the appropiate view with the Grid definition.
@(Html.Telerik().Grid(Model)
           .Name("Items")
           .Columns(columns =>
               {
                   columns.Bound(o => o.GTIN);
                   columns.Bound(o => o.ArticleNumber).Title("Artikelnummer");
                   columns.Bound(o => o.BranchNumber).Title("Filiale");
                   columns.Bound(o => o.Currency).Title("Währung").Width(80);
                   columns.Bound(o => o.DateTime).Format("{0:dd/MM/yyyy}").Title("Datum");
                   columns.Bound(o => o.ManufArticleNumber).Title("Hersteller");
                   columns.Bound(o => o.Quantity).Title("Menge");
                   columns.Bound(o => o.RetailPrice).Title("VK");
                   columns.Bound(o => o.Type).Title("Vorgang");
               })
               .DataBinding(dataBinding => dataBinding.Ajax().Select("AjaxBinding", "ArticleHistory"))
               .Scrollable()
               .Filterable()
               .Sortable()
               .Groupable()
               .Pageable(paging => paging.PageSize(10))
               .Footer(true)
   )

For example, the Column "Vorgangsart" shows the name of the transaction like Sales, GoodsReceipt, etc... but after paging only the Int-Values are shown. To illustrate this issue I attached the screeshots!

Here`s the code for the Ajax Binding in the Controller

#region AjaxBinding
 
[GridAction]
public ActionResult AjaxBinding()
{
    return View("SearchResult", new GridModel<DocumentItemDto>
                    {
                          Data = GetCachedData()
                    });
}
 
 #endregion
 #region GetCachedData
 
private IEnumerable<DocumentItemDto> GetCachedData()
{  
    return Session[Cache] as IEnumerable<DocumentItemDto>;
}
 
#endregion

I believe that it`s a JSON problem, but don`t know. I hope that someone can give me a tip on this. Thanks in advance.

5 Answers, 1 is accepted

Sort by
0
Kevin Burandt
Top achievements
Rank 1
answered on 04 Apr 2011, 01:59 PM
"I believe that it`s a JSON problem, but don`t know"

You can verify this one way or another by using Fiddler and examining the results from the controller.

Kevin
0
Ben
Top achievements
Rank 1
answered on 04 Apr 2011, 02:19 PM
Hi Kevin,

I checked it with Fiddler and there is the same result as in the Grid. 

For example:
{"data":[{"DateTime":"\/Date(1188813240000)\/","Type":2,"ArticleNumber":"13430000200","GTIN":"7610441817353","BranchNumber":"10","ManufArticleNumber":"15533","RetailPrice":39.9500007629395,"Quantity":1,"Currency":"___"}

But in the VS2010 Debugger the correct data is shown. Maybe the GridModel object converts the List<T> into JSON. As you can see in the Fiddler-Log the "Type":2 should be "Type":GoodsReceipt. 

Do you have a tip, how I can solve this problem? As I said, when i retireve the Data from the web-service in the first step the data looks fine in the grid.
0
Kevin Burandt
Top achievements
Rank 1
answered on 04 Apr 2011, 02:34 PM
I'm thinking it's because you are using server binding initially...

"@(Html.Telerik().Grid(Model)"

and subsequent bindings are Ajax, which is not being returned properly.  This page explains it fairly well http://www.telerik.com/help/aspnet-mvc/telerik-ui-components-grid-data-binding-ajax-binding.html

I've just been doing this same thing.  This is a pretty good example on how to get the json working properly http://demos.telerik.com/aspnet-mvc/grid/hierarchyajax

Kevin

0
Ben
Top achievements
Rank 1
answered on 04 Apr 2011, 03:46 PM
Hm, I have no hierachy and so no DetailView, it`s all in the MasterGrid and I`m not able to call .ToHtmlString(), because then the whole Grid isn`t rendered and the plain html is visible on the site :(
0
Ankit
Top achievements
Rank 1
answered on 19 Dec 2011, 06:59 PM
Hi Ben

I am also having the same problem. I am loosing all date formats and template columns. Did you find any solution? Please share if you did.

Thanks
Ankit
Tags
Grid
Asked by
Ben
Top achievements
Rank 1
Answers by
Kevin Burandt
Top achievements
Rank 1
Ben
Top achievements
Rank 1
Ankit
Top achievements
Rank 1
Share this question
or