I'm trying to create a grid filter for my kendo grid, the column shows an ID value and I want the filter to search based on the text.
For example: Column has employee ID and I want to search the grid with employee name but employee name is not a column. (
This is as per the requirement)
I've managed to make the autocomplete work and load the employee names but how to I get the employee ID and filter the grid?
Sample Code:
- @(Html.Kendo().Grid<abcModel>()
- .Name("abc")
- .DataSource(dataSource => dataSource
- .Ajax()
- .Model(model => model.Id(i => i.id))
- .Read(read => read.Action("Load", "abccontroller"))
- .PageSize(100)
- )
- .Filterable(filter => filter.Enabled(true))
- .Pageable(pager => pager.Enabled(true))
- .Resizable(resize => resize.Columns(true))
- .Columns(columns =>
- {
- columns.Bound(m => m.employeeID).Title("Employee Name").Filterable(f => f.UI("empFilter").Extra(false));
- })
- )
-
-
-
- <script type="text/javascript">
- function empFilter(element) {
- element.kendoAutoComplete({
- dataTextField: "Name",
- dataValueField: "employeeID",
- minLength: 3,
- filter: "contains",
- dataSource: {
- serverFiltering: true,
- serverSorting: true,
- transport: {
- read: "@Url.Action("Fetch", "abccontroller")",
- type: "GET",
- dataType: "json",
- parameterMap: function (data, action) {
- if (action === "read") {
- return {
- text: data.filter.filters[0].value
- };
- }
- }
- }
- }
- });
- }
- </script>