Telerik MVC Grid在重新加载时不进行排序

时间:2011-12-03 20:09:49

标签: asp.net-mvc-2 telerik-mvc

我的Telerik MVC网格是Ajax绑定的,我需要能够通过两个复选框(在顶部的DIV中)应用自定义过滤。选中复选框后,将设置参数并重新加载网格。这工作正常。在初始加载期间,数据根据Telerik中的排序设置进行排序,但在单击复选框后,数据按记录ID排序,不再按优先级排序。如果我然后按F5重新加载页面并且数据排序正确。排序可能是grid.rebind()的参数或OnDataBinding中提供的,但到目前为止我还没找到我要找的东西。

问题:如何在OnDataBinding或其他客户端事件中指定排序顺序。

这是我的代码:


<div style="float:right;width:600px;text-align:right">
    <span>My Items <%=Html.CheckBox("newItems") %></span>
    <span>Closed Items <%=Html.CheckBox("Inactive") %></span>
</div>

<% Html.Telerik().Grid<IssueModel>()
        .Name("Grid")
        .PrefixUrlParameters(false)
        .Columns(col =>
        {
            col.Bound(o => o.Title);
            col.Bound(o => o.Priority).Width(50).Title("Priority ID");
            col.Bound(o => o.PriorityName).Width(100).Title("Priority");
            col.Bound(o => o.IssueStateName).Width(100).Title("Status");
            col.Bound(o => o.AssignedToName).Width(140).Title("Assigned To");
        })
        .DataBinding(d => d.Ajax().Select("AjaxSelect", "Ticket", new { isNew = false, isInactive = false }))
        .ClientEvents(e => e.OnDataBinding("onDataBinding"))
        .Sortable(s => s
            .SortMode(GridSortMode.MultipleColumn)
            .OrderBy(order =>
                            {
                                order.Add(o => o.Priority);
                                order.Add(o => o.Sequence);
                            })
            )
        .Pageable(p => p.PageSize(15))
        .Filterable()
        .Render();
%>

<script type="text/javascript">
    function onDataBinding(e) {
        e.data = { 
            isNew: $("#newItems").is(':checked'), 
            isInactive: $("#Inactive").is(':checked') 
        };
        e.orderBy = "Severity~desc~Ranking~asc";
    }
    $("input[type='checkbox']").click(function () {
        var grid = $('#Grid').data('tGrid');
        var param = {
            isNew: $("#newItems").is(':checked'),
            isInactive: $("#Inactive").is(':checked')
        };
        grid.rebind(param);
    });
</script>

1 个答案:

答案 0 :(得分:2)

我找到了解决方案以防其他人需要答案。我使用grid.sort()代替grid.rebind(); sort方法采用以下格式的字符串:column-name dash direction。示例第一

<script type="text/javascript">
    function onDataBinding(e) {
        e.data = { 
            isNew: $("#newItems").is(':checked'), 
            isInactive: $("#Inactive").is(':checked') 
        };
    }
    $("input[type='checkbox']").click(function () {
        var grid = $('#Grid').data('tGrid');
        var param = {
            isNew: $("#newItems").is(':checked'),
            isInactive: $("#Inactive").is(':checked')
        };
        grid.sort("Severity-desc~Ranking-asc";);
        //grid.rebind(param);
    });
</script>
相关问题