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

Filter grid while typing the search box

2 Answers 538 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Roelande
Top achievements
Rank 1
Roelande asked on 22 Sep 2017, 01:56 PM

Hello,

Is there a way to filter the grid directly while typing without the need to hit the enter key?

For example when i type "b" in the name search box the grid show me all products with a "b" in it.

I couldn't find documentation regarding the possibility about this.

Thank you.

2 Answers, 1 is accepted

Sort by
1
Accepted
Georgi
Telerik team
answered on 26 Sep 2017, 11:25 AM
Hello Roelande,

Possible solution is to create custom filter widget. Once the change event of the filter input is triggered the filter method is called.  So you can execute the filtration by manually triggering the change event when the user types:

Column with custom filter in row filtering mode:
columns.Bound(x => x.YourColumn)
.Filterable(x=> x.Cell(y => y.Template("template").ShowOperators(false).Operator("contains")));

The template function:
function template(args) {
   args.element.css("width", "100%").addClass("k-textbox").on('input', function (e) {
        $(e.target).trigger("change");
   })     
}

For your convenience I have assembled small sample (filter-as-you-type-mvc.zip) which illustrates the aforementioned approach.


Regards,
Georgi
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Jon
Top achievements
Rank 1
Iron
commented on 21 Aug 2023, 09:16 PM | edited

Awesome!  Thanks!

To make mine look/feel like the adjacent built-in filters, I added the same classes to the parent span and used k-input-inner instead of k-textbox.  Also, to help convince the browser to stop trying to autofill, I added an autocomplete attribute.

function template(args) {
    args.element
        .css("width", "100%")
        .attr("autocomplete", "do-not-autofill")
        .addClass("k-input-inner")
        .parent('span').addClass("k-autocomplete k-input k-autocomplete-clearable k-input-solid k-input-md k-rounded-md")
        .on('input', function (e) {
        $(e.target).trigger("change");
    })
}

Anton Mironov
Telerik team
commented on 23 Aug 2023, 11:19 AM

Hi Jon,

Thank you for sharing this improvement with the community.

Feel free to contact me and the team if further assistance or information is needed.

Kind Regards,
Anton Mironov

0
Roelande
Top achievements
Rank 1
answered on 26 Sep 2017, 11:43 AM

Hi Georgi,

That was what I was looking for. Thank you

Tags
Grid
Asked by
Roelande
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Roelande
Top achievements
Rank 1
Share this question
or