bogdan / datagrid

Gem to create tables grids with sortable columns and filters
MIT License
1.02k stars 115 forks source link

How to filter data for an attribute that is not part of the Datagrid object? #299

Closed edulima closed 2 years ago

edulima commented 2 years ago

I am trying to add a filter to my page but the column name I am trying to filter is not part of the object assigned to the Grid. It was dynamically added to the table of results.

Given the object/model: Car

For example this: filter(:status, :enum, select: ['Good', 'Bad']) works fine, as :status is an attribute of Car.

In the case of this filter(:name, :enum, select: ['A1', 'A5']) fails because :name is part of another object and not part of the Car object. Of course this is just a sample object and adding :name is not an option for my real data model.

Query Error: Car.name Undefined column name.

Can this type of filter be achieved?

bogdan commented 2 years ago

Where is name stored? How the object that holds it is associated to Car?

edulima commented 2 years ago

I found a reference here that solved my problem. Thanks for your response.