【问题标题】:How do you manually sort a Kendo UI Grid in ASP MVC page?如何在 ASP MVC 页面中手动对 Kendo UI Grid 进行排序?
【发布时间】:2014-06-18 15:14:26
【问题描述】:

我有一个网格,如下所示。

如您所见,我已经将其设为可排序。但是当有人点击搜索时,我希望网格按特定字段排序——SurveyDueDate。

如何设置网格排序的字段以及搜索按钮单击事件中的javascript调用是升序还是降序?

我在网格上看到的所有内容只显示了如何使其可排序,并没有说明如何明确设置排序。

@(Html.Kendo().Grid<SurveyMaintenance.Models.StoreSurveyList>()
    .Name("idGridStoreSurveyList")
    .HtmlAttributes(new { ID = "idGridStoreSurveyList", Class = "k-grid-header" })
    .Columns(columns =>
    {
        columns.Bound(p => p.IsSelected)
            .ClientTemplate("<input type='checkbox' class='StoreSurveyListDeleteItemRequest' #= (IsSelected === true) ? checked='checked' : '' # onclick='StoreSurveyListFunctions.toggleStoreSurveyListDeleteItemRequestSelection(this)' />")
            .HeaderTemplate("<input type=\"checkbox\" id=\"toggleAllStoreSurveyListDeleteItems\"/>")
            .Width(40)
            .Filterable(false)
            .Sortable(false);

        columns.Bound(p => p.SurveyDueDate)
            .Template(@<text></text>)
            .ClientTemplate("#= kendo.toString(SurveyDueDate,'MM/dd/yyyy') #")
            .Width(130);

        columns.Bound(p => p.StoreCompleted)
            .Width(110);

        columns.Bound(p => p.SurveyName);

        columns.Bound(p => p.DeliveryDate)
            .Template(@<text></text>)
            .ClientTemplate("#= kendo.toString(DeliveryDate,'MM/dd/yyyy') #")
            .Width(130);

        columns.Bound(p => p.SupplierName)
            .Width(200);
    })
    .Sortable()
    .Filterable()
    .Navigatable()       
    .Resizable(resize => resize.Columns(true))
    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(500)
        .ServerOperation(false)
        .Events(events => events.Error("grid_error_handler"))
        .Model(model => { model.Id(p => p.SurveyID); })
        .Read(
           read => read.Action("GetStoreSurveyList", "StoreSurveyList").Data("additionalDataStoreSurveyList")
        )
    )
)

【问题讨论】:

    标签: javascript jquery asp.net-mvc sorting kendo-grid


    【解决方案1】:

    我想通了。

    在 javascript 调用中,我输入了以下代码:

        var kendoGrid = $("#idGridSurveyList").data("kendoGrid");
        var dsSort = [];
        dsSort.push({ field: "DeliveryDate", dir: "desc" });
        kendoGrid.dataSource.sort(dsSort);
    

    剑道网格的数据源有一个排序方法,你可以传递一个数组来保存排序的字段和方向。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-09
      • 1970-01-01
      • 2012-07-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多