How to customize grid filter row autocomplete?

1 Answer 288 Views
AutoComplete Filter Grid
Z
Top achievements
Rank 1
Iron
Z asked on 15 Jun 2021, 06:12 AM | edited on 15 Jun 2021, 07:09 AM

Hello,

 

i'm using MVC5 Razor helper to create grid and i'm trying to show specific autocomplete values in filter row. As i undestood it from forums and docs i have to replace standard filter row input by manually creating kendoAutoComplete(...) with my own dataSource, as shown for example here with classic filter menu:

https://demos.telerik.com/aspnet-mvc/grid/filter-menu-customization

or here with filter row:

https://www.telerik.com/forums/server-side-filtering-with-row-filter-mode-filters-too-soon!

My custom JS autocomplete:

<script>
function onFilterAutocomplete(e)
{
	e.element.kendoAutoComplete({
		filter: 'contains',
		dataSource: {
			serverFiltering: true,
			serverSorting: true,
			transport: {
				read: '@Url.Action("FilterAutocompleteAsync")'
			}
		}
	});
}
</script>

My server method:

[HttpPost]
//[ValidateAntiForgeryToken]
public async Task<JsonResult> FilterAutocompleteAsync([DataSourceRequest]DataSourceRequest dataSourceRequest) => Json(/*... db stuff...*/);

When i try to replace input by defining:

columns.Bound(x => x.ColumnName).Filterable(x => x.Cell(y => y.Template("onFilterAutocomplete")));

my JS function is executed on grid init and no errors are shown in browser console. But when i try to filter, the automatic autocomplete on filter input keeps showing values as normaly from grid dataSource (standard behaviour) and my controller method won't get called.

If i try to replace input by defining:

columns.Bound(x => x.ColumnName).Filterable(x => x.UI("onFilterAutocomplete")));

my JS function won't get called at all.

 

What am i doing wrong here?

 

PS: I've tried with following versions:

telerik.ui.for.aspnetmvc.hotfix.2019.2.619.commercial.digitally-signed

and

telerik.ui.for.aspnetmvc.hotfix.2021.2.511.commercial.digitally-signed

Z
Top achievements
Rank 1
Iron
commented on 15 Jun 2021, 06:32 AM | edited

So i've tried to add

placeholder: '~test~'

attribute to kendoAutoComplete init object and after grid init, no placeholder can be found in the filter row column input, so that custom autoComplete won't get created ever, not even with the Template.

1 Answer, 1 is accepted

Sort by
0
Accepted
Z
Top achievements
Rank 1
Iron
answered on 15 Jun 2021, 10:51 AM
Ha, the Template variant is working, but i've executed grid.setOptions({ columns: ... }) after grid init, which re-did filters once again, but without calling template function again, so beware.
Tags
AutoComplete Filter Grid
Asked by
Z
Top achievements
Rank 1
Iron
Answers by
Z
Top achievements
Rank 1
Iron
Share this question
or