This is a migrated thread and some comments may be shown as answers.

Kendo Grid filter with autocomplete textbox with text and value in ASP.Net MVC

3 Answers 1513 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nigel
Top achievements
Rank 1
Nigel asked on 25 Feb 2018, 10:19 PM

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?

 

@(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>

 

3 Answers, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 27 Feb 2018, 04:53 PM
Hi Nigel,

It would be easier to use a ForeignKey column in your Grid, as shown in this demo:
Grid / ForeignKey column

Look at the Category column, which is bound to the CategoryID field and the filter displays a dropdown with the category text values.

If you prefer to keep the custom approach, you can check this example to see how to apply the selected value as a Grid filter:
Use MultiSelect for Column Filtering

Regards,
Tsvetina
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Nigel
Top achievements
Rank 1
answered on 27 Feb 2018, 10:19 PM

Hi Tsvetina,

The main purpose is to avoid loading all the data in a dropdown (as the data is too large) and have it fill in an autocomplete textbox

0
Tsvetina
Telerik team
answered on 01 Mar 2018, 04:06 PM
Hi Nigel,

In this case, keep the AutoComplete and follow the example from this article to apply the selected value as a filter in the Grid:
Use MultiSelect for Column Filtering

Regards,
Tsvetina
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Chris
Top achievements
Rank 1
commented on 28 May 2024, 04:53 PM

Hello Tsvetina,

It seems the link here in the comments is broken. Also is that solution still applicable?

 

Thanks,

Chris

Martin
Telerik team
commented on 30 May 2024, 07:54 AM

Hello, Chris,

Here you will find the example mentioned. It is working correctly with the latest version.

Let me know if you have any questions.

Tags
Grid
Asked by
Nigel
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Nigel
Top achievements
Rank 1
Share this question
or