4

我在我的 KendoGrid 中使用了 kendo Auto Complete,它现在工作正常,但它只搜索或仅从一列中获取数据,

我希望它在多个列中进行搜索。

这是我在 KendoGrid 中的自动完成代码。

 $(function(){
    $("#EmployeeGrid").kendoGrid({
        dataSource:{
            serverPaging: true,
            serverFiltering: true,
            pageSize: 5,
            transport: {
                read: "<?php echo base_url() ?>index.php/hr_management/manage_hr/list_view"
            },
            schema:{
                data: "data",
                total: "total"
            }
        },
        toolbar: kendo.template($("#toolbarTemplate").html()),
        pageable: {
            input:true,
            numeric:false
        },
        columns: [
            {
                field: "EmployeeID",
                hidden:true
            },
            {
              field: "FileNo",
              title: "File Number"
            },
            {
                template:"#= FirstName # #= LastName #",
                title: "Full Name"
            },
            {
                field:"City",
                title:"City"
            },
            {
                field:"AddressLine1",
                title:"Address 1"
            },

            {
                field:"WorkPhone",
                title:"WorkPhone"
            },
            {
                field:"MobileNo",
                title:"Mobile No"
            },
            {command: { text: "View", click: showDetails }, title: " ", width: "140px"},
            {command: { text: "Edit", click: EditUserDetails }, title: " ", width: "140px"}
        ]
    });

});
var autoCompleteUsers = $("#employees").kendoAutoComplete({
    minLength: 3,
    dataTextField: "FileNo",
    dataSource: {
        serverFiltering: true,
        transport: {
            read: {
                type: "GET",
                dataType: "json",
                contentType:'application/json; charset=utf-8',
                url: "<?php echo base_url() ?>index.php/hr_management/manage_hr/search_employee/",
                data: function (arg){
                    return {FileNo : autoCompleteUsers.data("kendoAutoComplete").value()};
                }
            }
        }
    },
    change: onChangeAutoComplete
});
function onChangeAutoComplete(){
    var value = this.value();
    var grid = $('#EmployeeGrid');
    if (value) {
        grid.data("kendoGrid").dataSource.filter({ field: "FileNo", operator: "Contains", value: value });
    } else {
        grid.data("kendoGrid").dataSource.filter({});
    }
}


function showDetails(e) {
    e.preventDefault();
    $('.action_button').html('');
    var row = $(e.target).closest("tr");
    var item = $("#EmployeeGrid").data("kendoGrid").dataItem(row);
    $.ajax({
        type: "POST",
        url: "<?php echo base_url().'index.php/hr_management/manage_hr/view_employee_profile/'?>"+JSON.parse(item.EmployeeID),
        success: function(output_string){
            var data = output_string.split("MyMark_Employee");
            $('.second_column_content_container').html(data[0]);
            $('.action_button').html(data[1]);

            $("#createEmployee").hide();
        },
        error: function(data){
            alert("error");
        }
    });

}


function EditUserDetails(e) {
    e.preventDefault();
    $('.action_button').html('');
    var row = $(e.target).closest("tr");
    var item = $("#EmployeeGrid").data("kendoGrid").dataItem(row);
    $.ajax({
        type: "POST",
        url: "<?php echo base_url().'index.php/hr_management/manage_hr/edit_employee_details/'?>"+JSON.parse(item.EmployeeID),
        success: function(output_string){
            var data = output_string.split("MyMark_Employee");
            $('.second_column_content_container').html(data[0]);
            if(data[1]!= " ")
            {
                $('.action_button').html(data[1]);
            }

        },
        error: function(data){
            alert("error");
        }
    });

}

该怎么办?我需要定义多个dataTextField:吗?需要建议。

4

1 回答 1

3

好问题。我想知道同样的事情。

查看剑道代码(kendo.web.min.js)后,似乎无法为属性 dataTextField 定义多个字段。看起来只允许一个字段。

一种解决方法是在模型中添加一个字段,其中包括(以字符串形式)您要搜索的所有字段。然后将 dataTextField 设置为该字段。这不是一个理想的解决方案,但它有效。

于 2013-05-09T21:06:52.303 回答