在进行服务器过滤时,Kendo UI组合框会冻结

时间:2016-06-22 16:17:28

标签: javascript jquery asp.net-mvc kendo-ui kendo-asp.net-mvc

我需要将大约6000条记录绑定到组合框。当用户输入至少2个字符时,我正在对它进行服务器过滤。它第一次工作正常,但当我清除组合框时,我的页面冻结了。

以下是我启动组合框的方法。

$("#myList").kendoComboBox({
        filter: "startswith",
        dataTextField: "xName",
        dataValueField: "xId",
        template: '<span>#:xName# (#:gName#-#:gmName#)</span>',
        dataSource: viewModel.get("mydataList"),
        height: 400,
        autoBind: false,
        minLength: 2,
    }).data("kendoComboBox");

以下是我指定数据源的方法:

mydataList= new kendo.data.DataSource({
        transport: {
            read: {
                dataType: "json",
            },
            parameterMap: function (options, operation) {
                if (operation !== "read" && options.models) {
                    return {
                        models: kendo.stringify(options.models)
                    };
                }
            }
        },
        serverFiltering: true
    }
    );

另外请建议我是否可以隐藏下拉箭头。

1 个答案:

答案 0 :(得分:0)

您正在做的不是服务器过滤。仅仅因为你设置了serverFiltering: true并不意味着你正在进行服务器过滤。该设置只是告诉数据源您正在使用服务器筛选,但您需要实际实现它。你有6000条记录,这很多,这就是你的组合框冻结的原因。此外,你正在使用asp.net MVC,问题是用Kendo asp.net MVC标记的,所以你应该使用Razor语法。这是如何做到的。

您的ComboBox:

@(Html.Kendo().ComboBox()
      .Name("myList")
      .DataTextField("xName")
      .DataValueField("xId")
      .Template("<span>#:xName# (#:gName#-#:gmName#)</span>")
      .Filter("startswith")
      .AutoBind(false)
      .Height(400)
      .MinLength(2)
      .DataSource(source => {
          source.Read(read =>
          {
              read.Action("GetMyList", "MyController");
          })
          .ServerFiltering(true);
      })
)

然后在您的控制器(我的示例中为MyConteroller)中,您将有一个返回已过滤列表的操作:

public JsonResult GetMyList(string text) {
    // Here you put the logic to filter the data you had in myDataList in your question
}