Grid does not filter on certain properties.

1 Answer 15 Views
Grid
Andi
Top achievements
Rank 1
Iron
Iron
Andi asked on 04 Apr 2024, 01:05 PM | edited on 04 Apr 2024, 01:09 PM

I am trying to filter through a model lets say:

 

public class Cat

{    

     public int Id {get; set;}

     public int ColorId {get; set; }

}

public class Color

{

    public int ColorId { get; set; }

    public string? Color { get; set; }

}

 

in the controller :

 

public IActionResult GetCatsColors([DataSourceReques] DataSourceRequest request)

{

    var catColor = (from c in _catContext..Cats.ToList()

                              join v in _colorContext.Colors.ToList() on c.ColorId equals v.ColorId

                              select new ColorCat

                             {

                                   Colori = v.Color,

                                   CatId = c.Id

                             }).ToList();

                var jsonCat = catColor.ToDatasourceResult(request);

                return Json(jsonCat);

}

 

the view:

 

 @(Html.Kendo().Grid<TelerikOrderBossProduction.ViewModels.ColorCat>()

      .Columns(col =>

      {

             col.Bound(t => t.Id);

             col.Bound(t => t.Colori);

     }

     .Filterable(f => f.Mode(GridFilterMode.Row))

     .etc

 

    Now when I try to filter through the Id I get the grid to respond but when I filter by Colori I do not get a response

    and I have noticed, Error 500. Server internal error.

 

   I also have tried creating a view in the database but the same result appears. It looks like it only filters from one class but not the other.

 

  ArgumentException: Invalid property or field - 'Colori' for type: Cat

 

 

1 Answer, 1 is accepted

Sort by
0
Anton Mironov
Telerik team
answered on 09 Apr 2024, 08:21 AM

Hi Andi,

Thank you for the code snippets and the details provided.

The Telerik UI Components are responsible for visualizing the provided data. 

Yes, you are totally correct - the 500 Error is an Internal Server Error. It is not caused by the Telerik Components but by the BackEnd.

If you are using the "GetCatsColors" Method, I would recommend implementing the ToDataSourceResult as well. In the following demo feel free to use the implementation of the Controller as an example. The code is placed in the "View Source" tab:

Additional information about the Filtering functionality can be found in the following article:

 

Kind Regards,
Anton Mironov
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages. If you're new to the Telerik family, be sure to check out our getting started resources, as well as the only REPL playground for creating, saving, running, and sharing server-side code.
Andi
Top achievements
Rank 1
Iron
Iron
commented on 09 Apr 2024, 12:33 PM

So the data does get visualized and is also available as JSON but the filtering does not work (for the join object).

Lets say the object Color joins the main object Cat, data can be visualized and filtered through and only the main Object fields, not the other object has been joined to.

If I were to utilize the view without Telerik grid, filtering works on every field. I realized that the grid cannot filter through complex data types. (ex var cat = _catContext.Include(x => x.Colors).ToList(); because of not being able to map based on the API, and therefore throws error 500.

To the others having issues I would suggest adding those fields to the base model, to pass through the issue. Hope this helps others in the future.

 

 

Anton Mironov
Telerik team
commented on 12 Apr 2024, 07:53 AM

Hi Andi,

Yes, you are totally correct and I confirm - the fields should be added to the base Model.

Thank you for sharing this with the community.

Best Regards,
Anton Mironov

Tags
Grid
Asked by
Andi
Top achievements
Rank 1
Iron
Iron
Answers by
Anton Mironov
Telerik team
Share this question
or