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

[Solved] Grid loses orderBy on rebind

2 Answers 126 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.
Travis
Top achievements
Rank 1
Travis asked on 06 Oct 2011, 06:03 PM
I'm using ajax to bind my grid and I have a default sortable expressions defined like so:
.Sortable(sorting => sorting.OrderBy(sortOrder => sortOrder.Add(o => o.DateCreated).Descending()))

I'm defining filter values on "OnDataBinding" like so:

function onDataBinding(e) {
    var filter = getFilter();
    e.data = filter;
}

When a drop down value is changed i'm rebining the grid, but for some reason the grid's sorting state is whiped out, i.e. the "orderBy" property of the grid is empty after doing a rebind.  So I have to reset it when rebinding like so:
function RebindGrid() {
        var grid = $('#Grid').data('tGrid');
        var sortOrder = grid.orderBy;
        grid.rebind({ orderBy: sortOrder });
        grid.orderBy = sortOrder;
    }

Why do I have to do this?  Shouldn't the grid remember its sorting expression on rebind? 

2 Answers, 1 is accepted

Sort by
0
Accepted
Georgi Tunev
Telerik team
answered on 07 Oct 2011, 02:59 PM
Hello Travis,

 This behavior is expected and is by design. The rebind() method resets the grid state whereas ajaxRequest() doesn't. For more information on the subject, please check the following section in the documentation:

http://www.telerik.com/help/aspnet-mvc/telerik-ui-components-grid-client-api-and-events.html#rebind

Best wishes,
Georgi Tunev
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
0
Travis
Top achievements
Rank 1
answered on 10 Oct 2011, 03:43 PM
Ah, I see.  ajaxRequest() was what I needed.  Thank you!
Tags
Grid
Asked by
Travis
Top achievements
Rank 1
Answers by
Georgi Tunev
Telerik team
Travis
Top achievements
Rank 1
Share this question
or