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

Grid custom filter for boolean field

9 Answers 2275 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nick
Top achievements
Rank 1
Nick asked on 07 Oct 2014, 12:38 PM
Hello,

I want to filter a Grid with Bound bool field by using a dropdown instead of normal radiobuttons.
Is this possible at all?

I have tried settings filterable.UI as follows:

columns.Bound(c => c.UnServiceable)
    .Title("U/S")
    .ClientTemplate("#if(UnServiceable) { #Yes# } else { #No# }#")
    .Filterable(filter => filter
        .Messages(m => m.Info(Strings.Filter_UnServiceable_Message))
        .UI("boolAsDropdown"))
    .Width(100);


However, the ​boolAsDropdown​ javascript function is never called. It seems to be unable to call this when using a boolean field as data column.
The same method is working fine with other column types (int, string).

If anyone could help me with this issue, this would be great.

Thank you in advance,
Nick

9 Answers, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 09 Oct 2014, 07:23 AM
Hi Nick,

This topic is already discussed in the following forum post:

Regards,
Vladimir Iliev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Brian
Top achievements
Rank 1
answered on 05 Apr 2019, 02:57 PM

I don't agree, I need exactly the same and am having the exact same problem, having read that alternate thread multiple times I see nothing in there that helps me solve this?

How, in MVC do we get a customised filter for Boolean columns?

0
Tsvetina
Telerik team
answered on 09 Apr 2019, 08:40 AM
Hi Brian,

The linked thread discusses that customizing the filter of a boolean column is not supported. Currently, the filter template function will be executed by the Grid but it is still not possible to replace the radio buttons with a DropDownList out of the box because the DropDownList has a text input at its base and the values in it will be strings.
There is a way to replace the string values with boolean ones at runtime, during the filter event, so with some customization, your requirement of showing a DropDownList should be achievable:
columns.Bound(p => p.Delivered).Filterable(filterable => filterable.UI("getBoolFilter"));

function getBoolFilter(input) {
    input.kendoDropDownList({
        dataSource: {
            data: [
                { text: "True", value: "true" },
                { text: "False", value: "false" }
            ]
        },
        dataTextField: "text",
        dataValueField: "value",
        valuePrimitive: true
    });
}

Then, on filter of the Grid, convert the values as needed:
.Events(e=>e.Filter("onFilter"))
function onFilter(e) {
    if (e.field === "Delivered") {
        if (e.filter && e.filter.filters && e.filter.filters.length > 0) {
            e.filter.filters[0].value = (e.filter.filters[0].value === "true");
        }
    }
}


Regards,
Tsvetina
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
Andreas
Top achievements
Rank 1
answered on 12 Aug 2019, 12:51 PM

Hi Tsvetina,

i would like to have a dropdown control for boolean fields in kendoGrid and i would like to have it in Row-Filter and in Menu (ColumnMenu). I've searched the Forums and ended up here but your provided solution is not working on my end. I use asp core 2.2 and the latest kendo controls.

The "getBoolFilter" function is never fired and the grid behaves exactly the same, no matter if i implement your solution or not. It is always the default Filter with the radiobuttons.

Any ideas or is there a working example with a boll column and a dropdown filter template anywhere?

Best Regards

0
Alex Hajigeorgieva
Telerik team
answered on 14 Aug 2019, 11:33 AM
Hello, Andreas,

I am pleased to let you know that the customisation of the filterable ui for boolean columns has now been made possible.

To create a dropdown list for the GridFilterMode.Menu - the Filterable.UI option is used.
To create a dropdown list for the GridFilterMode.Row - the Filterable.Cell.Template is used.

@(Html.Kendo().Grid<OrderViewModel>()
    .Name("grid")
    .Filterable(f=>f.Mode(GridFilterMode.Row))
    .Columns(columns =>
    {
       columns.Bound(p => p.Discontinued).Filterable(f=>f.Cell(cell=>cell.Template("boolDropDown")));
 
<script>
    function boolDropDown(args) {
        args.element.kendoDropDownList({
            dataSource: [{ value: true, text: "True" }, { value: false, text: "False" }],
            optionLabel: "--Select--",
            dataTextField: "text",
            dataValueField: "value"
        });
    }
</script>

Let me know in case further questions arise.

Regards,
Alex Hajigeorgieva
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
Brian
Top achievements
Rank 1
answered on 14 Aug 2019, 11:47 AM

Hi, thanks for getting back to us.

I assume this is possible with a new release of the tools?
Could you confirm the version please?

Thanks

 

0
Alex Hajigeorgieva
Telerik team
answered on 15 Aug 2019, 11:14 AM
Hello, Brian,

The column filter appears to work in version 2015.2.624 which is as far back as the Dojo goes for easy testing:

https://dojo.telerik.com/@bubblemaster/eYUBIbOC/2

Which version are you currently using?

Kind Regards,
Alex Hajigeorgieva
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
Andreas
Top achievements
Rank 1
answered on 16 Aug 2019, 09:17 AM

Hello Alex,

got it working, thank you for yout help. In case someone may have the same issue as i had:

I did what you suggested but with no avail. It was always the same result not matter what i did. The UI and the Template never showed. Finally i found it, it was my mistake. I built a custom global functionality to save and restore the grid state based on the getOptions and setOptions. As mentioned in the knowledgebase when you stringify the options, js-handlers need to be reassigned. That was my point. I always lost the UI-Templates because of the stringify-thing. I changed it and now everything works as expected!

Cheers

 

0
Alex Hajigeorgieva
Telerik team
answered on 19 Aug 2019, 02:10 PM
Hello, Andreas,

Thank you for enhancing the forum post. Indeed, standard JSON does not preserve function references.

https://docs.telerik.com/kendo-ui/api/javascript/ui/grid/methods/setoptions

And here is the knowledge base article:

https://docs.telerik.com/kendo-ui/knowledge-base/grid-persist-customized-filter

Kind Regards,
Alex Hajigeorgieva
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
Grid
Asked by
Nick
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Brian
Top achievements
Rank 1
Tsvetina
Telerik team
Andreas
Top achievements
Rank 1
Alex Hajigeorgieva
Telerik team
Share this question
or