Telerik专家,我需要你的帮助!
在我的网格中,数据通过.ClientEvents .OnDataBinding
绑定在客户端上。
我只是致电grid.dataBind(customData)
。显示数据,但分组,过滤,排序不起作用。是否可以在grid.dataBind调用后对内容进行分组或过滤?
现在它只是移动我的列并且不进行任何分组。排序和过滤也失败了。
你能告诉我一个简单的分组示例吗?没有任何服务器请求吗?
答案 0 :(得分:2)
据我所知,如果没有再次点击服务器,你就无法做到这一点。 但是你可以通过Ajax抛出JavaScript来实现它。
您需要做的就是这些方法将重新绑定您的网格:
// For filtering
grid.filter("propName~eq~youValue");
// For grouping
grid.group("column Title");
请注意,这是列标题而非属性名称,因此,如果您的媒体资源为“CustomerName
”且您的列标题为“Customer Name
”,则应传递列标题。
无论如何,这将对控制器进行Ajax调用以再次重新绑定Grid。
的更新强> 的
您的网格应设置为.EnableCustomBinding(true)
,您应该修饰控制器方法,使您的Ajax网格具有[GridAction(EnableCustomBinding = true)]
属性。
希望这有帮助
答案 1 :(得分:2)
您可能需要考虑使用Operation Mode feature中发布的Q2 2011 release。
客户端操作模式 - 此新模式允许排序等操作 寻呼,过滤或分组纯粹在客户端上执行 对服务器进行一次初始调用以检索所有数据。
客户端模式实施:
Html.Telerik().Grid(Model)
.Name("YourGrid")
.DataBinding(dataBinding => dataBinding
.Ajax()
.OperationMode(GridOperationMode.Client) // Set to Client
.Select("Select", "Home")
)
否则,要使用javascript手动分组,如下所示:
<script type='text/javascript'>
function yourGrid_onDataBinding(e){
//Grabs your Grid
var yourGrid = $("#yourGrid").data("tGrid");
//Removes any existing groupings
yourGrid.groups = [];
//Ensure the column you wish to group by is EXACTLY as it appears in the Grid
yourGrid.group("yourColumnName");
}
</script>
以下是来自Telerik MVC论坛的一些有用的线程,可能会帮助您解决问题,如果这对您来说不是一个可行的解决方案:
Client-Side Grouping | Has a great deal of code for client-side grouping operations
<强> Client-Side dataBinding | More client-side code, talks about ClientSideGroupHeaderTemplates 强>
<强> Grouping with OperationMode.Client | If you have any issues with OperationMode.Client 强>
答案 2 :(得分:1)
我在网格中正在做完全相同的事情。我正在使用2011.2.629,jQuery 1.6.2。我实际上这是为了外部过滤 - 所以我不使用内置过滤 - 但分组和排序都适合我。
我们需要一些代码,伙计。
正如其他人提到的那样,请确保您拥有以下内容:
dataBinding.Ajax().OperationMode(GridOperationMode.Client)
您的网格是否在运行时绑定?如果没有,请将其绑定到一个空的viewModel,它与您在dataBind()中使用的那个相同。另外,你如何绑定到新列表?它可能是你的onDataBinding()中的东西。