如何在 Kendo 下拉列表中按文本和值搜索。

How to search by text and value in Kendo Dropdown List.

$(document).ready(function() {
                $("#products").kendoDropDownList({
                    filter: "startswith",
                    dataTextField: "ProductName",
                    dataValueField: "ProductID",
                    dataSource: {
                        type: "odata",
                        serverFiltering: true,
                        transport: {
                            read: {
                                url: "http://demos.telerik.com/kendo-ui/service/Northwind.svc/Products",
                            }
                        }
                    }
                });
            });

如何在 kendo 下拉列表中同时按值和文本进行搜索。你可以找到一个更好的例子 here

现在我只能按文本搜索了。假设我想按员工 ID 和姓名一起搜索。现在我只能按名称搜索。

可能吗?或不。给我线索继续挖掘。

非常感谢您的帮助。

只需将 ServerFiltering 设置为 true 并在服务器端处理您的查询并响应结果....

下面是我的 angular 控制器:

$scope.reportingPersonOptoins = {
            filter: "startswith",
            autoBind: true,
            dataSource: {
                serverFiltering: true,
                transport: {
                    read: {
                        dataType: "json",
                        type: "POST",
                        url: baseurl + "employee/get_employee_list"
                    }
                }
            },
            dataTextField: "first_name",
            dataValueField: "employee_id",
            optionLabelTemplate: "---Select Reporting Person---",
            template: '<span>#: data.employee_id #, #: data.first_name # #: data.last_name # </span>',
            valueTemplate: '<span>#: data.employee_id #, #: data.first_name # #: data.last_name # </span>',
        };

这是我的服务器包装器

通过 :

接收值
 header('Content-Type: application/json');
 $receive = $this->input->post();
if (isset($receive['filter'])) {
        $data = $receive['filter']['filters'][0]['value'];
    } else {
        $data = NULL;
    }

和运行相应的查询

$this->db->select('hr_employee.employee_id, hr_employee.first_name, hr_employee.last_name, hr_employee_employment.branch_id')
            ->join('hr_employee_employment', 'hr_employee.employee_id = hr_employee_employment.employee_id')
            ->where(array("hr_employee.is_active" => 1, "hr_employee.is_admin" => 0));
    if ($data !== NULL) {
        $this->db->or_like("hr_employee.employee_id", $data);
        $this->db->or_like("hr_employee.first_name", $data);
        $this->db->or_like("hr_employee.last_name", $data);
    }
    $query = $this->db->get('hr_employee');

哇!!!干杯!!