2011-12-03 24 views
1

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

问题:如何在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> 

回答

2

我发现的情况下,其他的解决方案需要的答案。我用grid.sort()代替grid.rebind(); sort方法采用格式为:column-name破折号方向的字符串。示例第一

<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> 
+0

谢谢,我也有这个问题 - 解决方案是显而易见的,也是工作,如果orderBy为空(调用grid.sort('');) –