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

Kendo Grid Filter Enum.

3 Answers 449 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ermish
Top achievements
Rank 1
Ermish asked on 16 Oct 2013, 08:20 PM
I have a Kendo Grid where I filter based on an Enum. 
Let's say the Enum was:
public enum MyEnum
    {
        [Description("Null")] Null = -1,
 
        [Description("Yes")] Yes = 1,
 
        [Description("No")] No = 0,
    }

Kendo Grid:
.Filterable(filter => filter.Enabled(true)
                         .Operators(o => o.ForEnums(e => e.Clear()
                            .IsEqualTo("Equals")
                        .IsNotEqualTo("Not equal to")))
   )

and
.Filter(filter => filter.Add(p => p.myColumn).IsEqualTo(MyEnum.Yes))




I would like for the Filter to show only Yes or No options. Is there a way to do this?

3 Answers, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 17 Oct 2013, 06:52 AM
Hello Philip,

Yes, it is possible to modify the filter menu. I would recommend you to check our Filter menu customization demo for additional information.

Regards,
Alexander Popov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Jayesh Goyani
Top achievements
Rank 2
answered on 17 Oct 2013, 08:04 AM
Hello,

<script type="text/javascript">
 
    function filterMenuInit(e) {
        var firstValueDropDown = e.container.find("select:eq(1)").data("kendoDropDownList");
        var itemToRemove = firstValueDropDown.dataSource.at(2);
        firstValueDropDown.dataSource.remove(itemToRemove);
        firstValueDropDown.select(0);
 
        var firstValueDropDown2 = e.container.find("select:eq(4)").data("kendoDropDownList");
        var itemToRemove2 = firstValueDropDown2.dataSource.at(2);
        firstValueDropDown2.dataSource.remove(itemToRemove2);
        firstValueDropDown2.select(0);
    }
 
</script>
@(Html.Kendo().Grid<MvcApplication1.Models.TestModels>()
    .Name("Grid")
    .Columns(columns =>
    {
        columns.Bound(p => p.ID);
        columns.Bound(p => p.Name);
        columns.Bound(p => p.EnumID);
 
    })
    .Pageable(x => x.PageSizes(new int[] { 10, 20, 30, 50 }).Refresh(true))
    .Sortable()
    .Filterable(filter => filter.Enabled(true)
                         .Operators(o => o.ForEnums(e => e.Clear()
                            .IsEqualTo("Equals")
                        .IsNotEqualTo("Not equal to")))
   )
 
    .DataSource(dataSource => dataSource
        .Ajax()
            .Read(read => read.Action("Grid_Read", "Home"))
 
    )
    .Events(e => e.FilterMenuInit("filterMenuInit"))
)
public ActionResult Grid_Read([DataSourceRequest] DataSourceRequest request)
        {
            List<TestModels> models = new List<TestModels>();
 
            for (int i = 0; i < 50; i++)
            {
                TestModels t1 = new TestModels();
                t1.ID = i;
                t1.Name = "Name" + i;
                if (i % 2 == 0)
                {
                    t1.EnumID = MyEnum.Yes;
                }
                else
                {
                    t1.EnumID = MyEnum.No;
                }
                models.Add(t1);
 
            }
 
            return Json(models.ToDataSourceResult(request));
        }
public enum MyEnum
{
    Null = -1,
    Yes = 1,
    No = 0,
}
 
public class TestModels
{
    [Display(Name = "ID")]
    public int ID { get; set; }
 
    [Display(Name = "Name")]
    public string Name { get; set; }
 
    public MyEnum EnumID { get; set; }
 
}


Thanks,
Jayesh Goyani
0
Alexander Popov
Telerik team
answered on 17 Oct 2013, 09:29 AM
Hello again Jayesh,

I am not sure if I understand the attached screenshot correctly - it looks like you have achieved the desired behavior.
Please, let me know if I can assist you further.

Regards,
Alexander Popov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Ermish
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
Jayesh Goyani
Top achievements
Rank 2
Share this question
or