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

how to refresh a filter on databound

2 Answers 1433 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rui
Top achievements
Rank 1
Rui asked on 21 Sep 2017, 07:59 AM

I have a grid with a custom filter on one column 

    @(Html.Kendo().Grid<Model>()

          .Name("grid")

         .Events(e => e.FilterMenuInit("FilterMenuInit"))

          .Columns(columns =>

          {

              columns.Bound(e => e.DocumentType).Title("Title").Filterable(x => x.UI("SomeFunction")

                  .Extra(false)

                  .Operators(k => k

                      .ForString(str => str.Clear()

                          .IsEqualTo("Is equal to")

                          .IsNotEqualTo("Is not equal to")

                      ))

                  );

              columns.Bound(e => e.Something).Title("Title").Filterable(false);

              columns.Bound(e => e.SomethingElse).Title("AnotherTitle").Width(50);

          })

          .Filterable()

          .Sortable()

          .Pageable(x =>

          {

          ...

          })

          .DataSource(dataSource => dataSource

            ...

          )

    )

 

the dropdownllist of the filter has all the distinct values that are in the column

 

    function SomeFunction (element) {

        const distinctDocTypes = GetDistinctDocTypes();

 

        element.kendoDropDownList({

            dataSource: distinctDocTypes,

            optionLabel: "Select Doc Type",

            dataTextField: "Title",

            dataValueField: "Title",

            open: AdjustDropDownWidth

        });

    }

 

 

        private getDistinctDocTypes() {

            const data = $("#grid").data("kendoGrid").dataSource.data();

 

            const docTypes = (a => {

                var seen = {};

                return a.filter(e => seen[e.DocumentType] ? false : (seen[e.DocumentType] = true)).map(e => ({

                    Title: e.DocumentType

                }));

            })(data);

 

            return docTypes.sort((a, b) => a.Title.localeCompare(b.Title));

        }

 

THis works fine.

The thing is, if there is a refresh of the page and the number of distinct values is greater, i just want to add, not take, it does not change in the dropdown.

How can I reflect that change? Is there a event I can capture or so?

 

2 Answers, 1 is accepted

Sort by
0
Preslav
Telerik team
answered on 22 Sep 2017, 03:16 PM
Hello Rui,

A possible solution to achieve the desired behavior might be handling the filterMenuOpen event. In the event handler, get the new values using an approach similar to the one outlined in the provided code and create new dataSource with these values. After that, use the setDataSource method of the DropDownList to use the new data in the DropDown filter.
Please, give the above a try and let me know if it works for you.


Regards,
Preslav
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.
0
Rui
Top achievements
Rank 1
answered on 25 Sep 2017, 10:01 AM

Hi.
It works fine. Tks

Tags
Grid
Asked by
Rui
Top achievements
Rank 1
Answers by
Preslav
Telerik team
Rui
Top achievements
Rank 1
Share this question
or