Model view controller 剑道服务器端网格过滤/排序

Model view controller 剑道服务器端网格过滤/排序,model-view-controller,kendo-ui,Model View Controller,Kendo Ui,我真的不知道如何达到我的要求,即: 允许用户对完整数据集进行用户排序/筛选 服务器端初始默认筛选器 因此,基本上我想将客户机过滤器控件设置为服务器端定义的值。页面加载后,用户可以覆盖此设置并检索完整数据集的列表 我正在使用以下网格: @(Html.Kendo().Grid<SubscriptionViewModel>() .DataSource(dataSource => dataSource ... .ServerOpe

我真的不知道如何达到我的要求,即:

  • 允许用户对完整数据集进行用户排序/筛选
  • 服务器端初始默认筛选器
因此,基本上我想将客户机过滤器控件设置为服务器端定义的值。页面加载后,用户可以覆盖此设置并检索完整数据集的列表

我正在使用以下网格:

@(Html.Kendo().Grid<SubscriptionViewModel>()
      .DataSource(dataSource => dataSource
          ...
          .ServerOperation(true)

      )
      .Name("subscriptionsGrid")         
      .Columns(columns =>
      {
          ...
          columns.Bound(p => p.SubscriptionValidStatus).Filterable(filterable=>filterable.UI("subscriptionStatusFilter")).HeaderHtmlAttributes(new { style = "white-space: normal; vertical-align: top" });
          ....

      })          
      .Scrollable(a => a.Height("700px"))
      .Selectable(selectable => selectable
          .Mode(GridSelectionMode.Single)
      )
      ...
      .Sortable()
      .Filterable(filterable => filterable
        .Extra(false)
      )
      )
@(Html.Kendo().Grid())
.DataSource(DataSource=>DataSource
...
.ServerOperation(真)
)
.Name(“订阅网格”)
.列(列=>
{
...
columns.Bound(p=>p.SubscriptionValidStatus).Filterable(Filterable=>Filterable.UI(“subscriptionStatusFilter”)).HeaderHtmlAttributes(新的{style=“空白:正常;垂直对齐:顶部”});
....
})          
.可滚动(a=>a.高度(“700px”))
.可选(可选=>可选
.模式(GridSelectionMode.Single)
)
...
.Sortable()
.Filterable(Filterable=>Filterable
.额外(错误)
)
)

您可以使用客户端事件在页面加载时添加筛选器,而不是服务器端默认筛选。。。实际效果将是您的过滤器就位,此时用户可以选择列标题中的过滤器小部件来删除它,或者他们可以向其他列添加更多过滤器。我已经用我的一些代码来完成这项工作,并将其重命名为您的网格名称

试试这个

在网格定义中,添加如下事件:

.Events(events => events.DataBound("dataBoundSetFilter"))
然后,使用javascript函数设置具有首选筛选的列的筛选:

 <script type="text/javascript">

        // hasBound variable set on page load to false, will be set true after Grid databound event
        var hasBound = false;
        function dataBoundSetFilter(e) {
            // If the grid has not yet been data-bound, apply this here filter
            if (hasBound === false) {
                //alert("Start");
                // Get a reference to the grid
                var grid = $("#subscriptionsGrid").data("kendoGrid");
                // Apply a filter to the grid's datasource
                grid.dataSource.filter({ field: "SubscriptionValidStatus", operator: "eq", value: true });
                // Set hasBound = true so this won't be triggered again...
                hasBound = true;
            }
        }
    </script>

//HASBIND变量在页面加载时设置为false,将在网格数据绑定事件后设置为true
var hasbund=false;
函数dataBoundSetFilter(e){
//如果网格尚未进行数据绑定,请在此处应用此筛选器
如果(hasbund==false){
//警报(“启动”);
//获取对网格的引用
var grid=$(“#subscriptionsGrid”).data(“kendoGrid”);
//将筛选器应用于网格的数据源
grid.dataSource.filter({字段:“SubscriptionValidStatus”,运算符:“eq”,值:true});
//设置hasbund=true,这样就不会再次触发此操作。。。
hasbund=true;
}
}

您可以使用客户端事件在页面加载时添加筛选器,而不是服务器端默认筛选。。。实际效果将是您的过滤器就位,此时用户可以选择列标题中的过滤器小部件来删除它,或者他们可以向其他列添加更多过滤器。我已经用我的一些代码来完成这项工作,并将其重命名为您的网格名称

试试这个

在网格定义中,添加如下事件:

.Events(events => events.DataBound("dataBoundSetFilter"))
然后,使用javascript函数设置具有首选筛选的列的筛选:

 <script type="text/javascript">

        // hasBound variable set on page load to false, will be set true after Grid databound event
        var hasBound = false;
        function dataBoundSetFilter(e) {
            // If the grid has not yet been data-bound, apply this here filter
            if (hasBound === false) {
                //alert("Start");
                // Get a reference to the grid
                var grid = $("#subscriptionsGrid").data("kendoGrid");
                // Apply a filter to the grid's datasource
                grid.dataSource.filter({ field: "SubscriptionValidStatus", operator: "eq", value: true });
                // Set hasBound = true so this won't be triggered again...
                hasBound = true;
            }
        }
    </script>

//HASBIND变量在页面加载时设置为false,将在网格数据绑定事件后设置为true
var hasbund=false;
函数dataBoundSetFilter(e){
//如果网格尚未进行数据绑定,请在此处应用此筛选器
如果(hasbund==false){
//警报(“启动”);
//获取对网格的引用
var grid=$(“#subscriptionsGrid”).data(“kendoGrid”);
//将筛选器应用于网格的数据源
grid.dataSource.filter({字段:“SubscriptionValidStatus”,运算符:“eq”,值:true});
//设置hasbund=true,这样就不会再次触发此操作。。。
hasbund=true;
}
}

thx为您提供可能的解决方案Dinglemeyer

我刚刚想出了如何在服务器端实现它;加入:

.Filter(factory => factory.Add(model=> model.SubscriptionValidStatus).IsEqualTo("Aktiv"))

到数据源

thx为您提供可能的解决方案

我刚刚想出了如何在服务器端实现它;加入:

.Filter(factory => factory.Add(model=> model.SubscriptionValidStatus).IsEqualTo("Aktiv"))

到数据源

在你的网格声明中?我喜欢。。。我将窃取该片段,并替换我的团队的javascript默认过滤功能,以使用此本机剑道功能。很好的发现,el_buck0。我喜欢!!!在你的网格声明中?我喜欢。。。我将窃取该片段,并替换我的团队的javascript默认过滤功能,以使用此本机剑道功能。很好的发现,el_buck0。我喜欢!!!