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

Filter only if there are more then 10 items

3 Answers 125 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Robert Madrian
Top achievements
Rank 1
Veteran
Iron
Robert Madrian asked on 14 Sep 2018, 02:17 PM

Hello,

We have some DDL with more then 10 items and also with less than 10 items we use a EditorTemplate where the filter setting is:  .Filter("contains")
but it makes no sense to habe a filter if there are only a few rows - in the DataBound event I wanted to disable/enable the filter like this but it doesn't work:

function FilterSetting(e) {
        var ds = this.dataSource.data();
        if (ds.length > 10) {
            this.options.filter = "contains";
        } else {
            this.options.filter = "none";
        }
    }

 

How can I display the filter depending on how many rows are available?

 

robert

 

3 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 17 Sep 2018, 06:34 PM
Hi Robert,

The filtering of the grid on a general scale is controlled by the .Filterable() property. If you want to disable it depending on some condition, you can use the setOptions method to achieve that:
https://docs.telerik.com/kendo-ui/api/javascript/ui/grid/methods/setoptions

Here is a sample which achieves this requirement:
$(document).ready(function (e) {
    var grid = $("#grid").data("kendoGrid");
    grid.dataSource.one("change", function (e) {
        grid.setOptions({
            filterable: grid.dataSource._pristineTotal > 10
        });
    });
});

Give it a try and let me know if it works for you.

Regards,
Eyup
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Robert Madrian
Top achievements
Rank 1
Veteran
Iron
answered on 18 Sep 2018, 06:08 AM

I'm Talking About the dropdownlits not the grid - re-read my post please…

 

robert

0
Eyup
Telerik team
answered on 18 Sep 2018, 06:38 AM
Hi Robert,

I'm sorry for missing this. The script logic in this case is analogous, here is the solution for the DropDownList component:
<script>
    $(document).ready(function (e) {
        var ddl = $("#orders").data("kendoDropDownList");
        ddl.dataSource.one("change", function (e) {
            ddl.setOptions({
                filter: ddl.dataSource._pristineTotal > 10 ? "contains" : "none"
            });
        });
    });
</script>

That should do the trick.

Regards,
Eyup
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
DropDownList
Asked by
Robert Madrian
Top achievements
Rank 1
Veteran
Iron
Answers by
Eyup
Telerik team
Robert Madrian
Top achievements
Rank 1
Veteran
Iron
Share this question
or