Error when first filtering and ordering when filters include a dynamic condition
- When the filters contain a dynamic condition filter.
- Use one of the filters doesn't matter which one.
- Order one of the columns This results in an error "#Datagrid::Filters::DynamicFilter::FilterValue:0x000000011df1fc70"
I think the same thing happens in the demo https://datagrid.herokuapp.com/users as this also shows an error, but no error for the timesheet which does not include a dynamic condition filter.
I found the issue in the creation of the order links
def datagrid_order_path(grid, column, descending)
column = grid.column_by_name(column)
query = request&.query_parameters || {}
ActionDispatch::Http::URL.path_for(
path: request&.path || "/",
params: query.merge(grid.query_params(order: column.name, descending: descending)),
)
end
query = { grid: { condition: { field: '', operation: '', value: '' } } }
grid.query_params(order: column.name, descending: descending) = { grid: { condition: #<Datagrid::Filters::DynamicFilter::FilterValue:0x000000011df1fc70>, order: '', descending: true)
The query_params returns incorrect params and overwrite the correct query params. As a workaround I copied this method locally, and used the grid.to_param to merge the order and descending params to the query
def datagrid_order_path(grid, column, descending)
column = grid.column_by_name(column)
query = request&.query_parameters || {}
ActionDispatch::Http::URL.path_for(
path: request&.path || '/',
params: query.deep_merge("#{grid.to_param}": { order: column.name, descending: }),
)
end
But this goes deeper and calling grid.attributes which is used to create the query_params already returns the condition param as an object instead of an hash
Fixed the issue in 2.0.7. Please check.
Yes it works thank you
FYI There were some side effects people reported. So, I had to fix them and release 2.0.8. Please make sure you use the latest version because those fixes may break your use case.