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

时间:2015-04-08 10:20:04

标签: javascript angularjs kendo-ui kendo-dropdown

$(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&一起说出来。现在我只能通过名字搜索。

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

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

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

下面是我的角度控制器:

$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');

哇!!!欢呼声!!