【问题标题】:Kendo Server Side Grid Filtering/SortingKendo 服务器端网格过滤/排序
【发布时间】:2016-04-20 13:02:34
【问题描述】:

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

  • 允许用户对完整数据集进行用户排序/过滤
  • 服务器端初始默认过滤器

所以基本上我想将客户端过滤器控件设置为服务器端定义的值。页面加载后,用户可以覆盖此设置并检索完整数据集的列表。

我正在使用以下网格:

@(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)
      )
      )

【问题讨论】:

    标签: model-view-controller kendo-ui


    【解决方案1】:

    感谢您可能的解决方案 Dinglemeyer

    我刚刚弄清楚如何在服务器端进行操作;通过添加:

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

    到数据源!

    【讨论】:

    • 那在你的网格声明中?我喜欢……我要偷那个 sn-p 并替换我团队的 javascript 默认过滤功能来使用这个本机剑道功能。很好的发现,el_buck0。我挖了!!!
    【解决方案2】:

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

    试试这个!

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

    .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>
    

    【讨论】:

      【解决方案3】:

      我正在寻找行过滤器,并在其中添加多个过滤器。我发现下面的文章很有帮助。它使用 [Kendo.Mvc.CompositeFilterDescriptor] 过滤

      https://www.telerik.com/forums/how-do-i-use-compositefilterdescriptor-to-set-the-initial-datasource

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多