2013-04-15 195 views
4

我已經使用劍道自動完成我的KendoGrid, 它工作正常現在,但它只能搜索或從對面只有一列中獲取數據,劍道自動完成搜索多列

我希望它在多個搜索列。

這是我在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:? 需要建議。

回答

3

好問題。我想知道同樣的事情。

查看Kendo代碼(kendo.web.min.js)後,看起來好像不可能爲屬性dataTextField定義多個字段。它看起來只允許一個字段。

解決方法是在模型中添加一個字段,其中包含(以字符串形式)所有要搜索的字段。然後將dataTextField設置爲該字段。這不是一個理想的解決方案,但它的工作原理。