Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2350
IgGrid Filtering by an Enum column
posted

Hi,

I have an MVC grid that uses a DataSourceUrl to get a JsonResult from the controller.  When I try to filter by a field that is based on an Enum, the controller crashes with the error "Argument types do not match" when trying to retrieve the filtered data.

What is the correct way to filter by enums in the grids?

Here is a quick example of how I'm doing this:

    public class RowModel
    {
        public int Field1 { get; set; }
        public Options Field2 { get; set; }
    }
    public enum Options
    {
        Default,
        OptionA,
        OptionB
    }
        public GridModel CreateGrid2()
        {
            GridModel gridModel = new GridModel();
            gridModel.ID = "grid1";
            GridFiltering filtering = new GridFiltering();
            gridModel.Features.Add(filtering);
            gridModel.PrimaryKey = "Field1";
            gridModel.Columns.Add(new GridColumn("Field1", "Field1", "numeric", "150px"));
            gridModel.Columns.Add(new GridColumn("Field2", "Field2", "numeric", "150px"));
            gridModel.DataSourceUrl = Url.Action("GetData");
            return gridModel;
        }
        public JsonResult GetData()
        {
            GridModel model = CreateGrid2();
            List<RowModel> rowModelList = new List<RowModel>();
            for (int i = 0; i < 100; i++)
            {
                rowModelList.Add(new RowModel() { Field1 = i, Field2 = Options.OptionA });
            }
            model.DataSource = rowModelList.AsQueryable();
            return model.GetData();
        }
Thanks,
Paul