Mehedi Hasan
Mehedi Hasan

Reputation: 61

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",
                            }
                        }
                    }
                });
            });

How can i search by value and text together in kendo dropdown list. a better example you can find here

Now i can search by only text. suppose I want to search by employee id & name together. now i can search by only name.

is it possible? or not. Give me clue to continue digging.

I will appreciate your help.

Upvotes: 2

Views: 3338

Answers (1)

Mehedi Hasan
Mehedi Hasan

Reputation: 61

Just on the ServerFiltering to true and handle your query in server side and response the result....

below is my angular controller:

$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>',
        };

and this is my server wrappers

receive the value by :

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

and run the query accordingly

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

Wow!!! cheers!!

Upvotes: 0

Related Questions