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

Custom Ajax Binding - GridCommand values resetting

8 Answers 189 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.
Cyndie
Top achievements
Rank 1
Cyndie asked on 06 Aug 2010, 07:31 PM
I've followed the fix in this thread regarding the GridCommand values being reset and it is not working for me.  The only difference that I see is that I'm using Custom Ajax Binding instead of Custom Server Binding.  I do have EnableCustomBinding set in the grid. 

[GridAction(EnableCustomBinding = true, GridName="Grid")]
public ActionResult Index_Ajax(GridCommand command)
.EnableCustomBinding(true)

When I step through the code and click on a column to sort, the GridCommand is reset.  All Descriptors have a count of 0, Page=0 and PageSize=100.

Thanks.

8 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 09 Aug 2010, 07:18 AM
Hi Cyndie,

 Did you check our online demo which demonstrates custom binding? How is your setup different?

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Cyndie
Top achievements
Rank 1
answered on 09 Aug 2010, 02:37 PM
Thanks for your response!

This link didn't work for me, but yes I did follow the demo, the help pages and the forum threads related to custom binding.  The only difference that I see is that I do not pass 'data' in ActionResult Index (because if I do the grid uses server binding the first time it is displayed and my client template formatting is not there).  I also do not pass command to my query in Index_Ajax because command is reset when Index_Ajax is called, so I get an empty grid if a pass command.    I want it to requery the data anyways because I'm using a custom form to allow multiple ORs for filtering each column.  I want to retain the number of rows per page (I have a dropdown for the user to select how many rows per page which I followed the example in this forum to create, but set a default to 100 because the value isn't retained) and would like to allow the user to sort, but there are no sort values passed back, so I took that out for now.

Maybe you can see something that I'm overlooking.

Thanks.

View
     <%= Html.Telerik().Grid(Model)
        .Name("Grid")
        .DataBinding(dataBinding => dataBinding.Ajax().Select("Index_Ajax", "Alarm"))
        .ClientEvents(events => 
            {
                events.OnDataBound("onDataBound");
                events.OnRowDataBound("onRowDataBound");
            })
        .EnableCustomBinding(true)
        .Columns(columns =>
        {
            columns.Bound(o => o.Audible).ClientTemplate("<# if (Audible == true) {#><img id='audimg' src='../images/audalarm.png' alt='Audible Alarm' <#} else if (Unackiss == true) {#><img id='audimg' src='../images/alarm.png' alt='Visible Alarm' <#} else {#><img id='audimg' src='../images/blank.png' alt='Logged only' <#} if (Abnormal == true) {#> style='border:1px solid magenta;' /><#} else {#> /><#}#>").Title("").Sortable(false);
            columns.Bound(o => o.TimeLocal).Title("Event-Time");
            columns.Bound(o => o.AlarmText).Title("Text");
            columns.Bound(o => o.Priority);
            columns.Bound(o => o.Loc).Title("Location");
            columns.Bound(o => o.Cat).Title("Category");
            columns.Bound(o => o.ExcDef).Title("Exception");
        })
        .Ajax(ajax => ajax.Action("Index_Ajax", "Alarm")) 
        .Pageable(pager => pager.PageSize(100).Position(GridPagerPosition.Both).Total((int)ViewData["total"]))
        .Sortable(sorting => sorting.OrderBy(sortOrder => sortOrder.Add(o => o.TimeLocal).Descending()))
%>


NOTE: when stepping through with the debugger, command is reset before the line to requery the database, so the new GridCommand in my call to query the data is not what is causing it to reset.


Controller:
public ActionResult Index()
{
    IEnumerable<AlarmEntry> data = _repository.QueryAlarmEntries(new GridCommand(), userData);
    ViewData["total"] = userData.alarmRowCount; 
    return View();
}
[GridAction(EnableCustomBinding = true, GridName="Grid")]
public ActionResult Index_Ajax(GridCommand command)
{
    if (command.Page != 0)
        userData.alarmPage = command.Page;
    userData.alarmPageSize = command.PageSize;
    userFile.saveUserData(userData, host);
    IEnumerable<AlarmEntry> data = data = _repository.QueryAlarmEntries(new GridCommand(), userData);
    ViewData["total"] = userData.alarmRowCount;
    return View("Index", new GridModel 
    {
       Data = data,
       Total = (int)ViewData["total"]
    });
}
0
Atanas Korchev
Telerik team
answered on 09 Aug 2010, 03:06 PM
Hello Cyndie,

Unfortunately I don't see anything out of the ordinary. I am sending a sample project which shows custom ajax binding.

I hope this helps,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Cyndie
Top achievements
Rank 1
answered on 09 Aug 2010, 03:22 PM
Thanks Atanas.

I see that you are not passing the gridcommand back to the ajax method here.  I don't see where you are setting 'page' and 'search' in the view on the client side to pass back to _Index?
0
Atanas Korchev
Telerik team
answered on 09 Aug 2010, 03:43 PM
Hello Cyndie,

I am attaching a modified example.

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Cyndie
Top achievements
Rank 1
answered on 10 Aug 2010, 02:39 PM
I have discovered two things.  Apparently, adding GridName="Grid" doesn't work for custom ajax binding, so the forum I linked to above must be for custom server binding only.  When I removed that, I got command data for my Index_Ajax method.

The second thing is I have a custom filter and search that calls a different method and I guess I cannot pass GridCommand to it, but I can work around that as long as the ajax method works.

Thanks
0
jpchenot
Top achievements
Rank 2
answered on 29 Sep 2011, 02:22 PM
Hi Atanas.

It still doesn't show how you are setting the page on the client side.

For some reason, everytime I rebind the grid via Grid.Rebind(), it resets itself to page = 1 and pagesize = 10, which is my default.

Any idea?

Also how can you access the command object from client-side?

Thanks.

Jean-Philippe
0
Rosen
Telerik team
answered on 30 Sep 2011, 12:08 PM
Hi Jpchenot,

Indeed, calling rebind will reset the grid state as described in the documentation.

Regards,
Rosen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
Tags
Grid
Asked by
Cyndie
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Cyndie
Top achievements
Rank 1
jpchenot
Top achievements
Rank 2
Rosen
Telerik team
Share this question
or