Closed egracens closed 4 years ago
The solution I found is to write custom DSL for it and render columns in custom datagrid view depending on settings.
I use the following strategy in my project:
module SharedColumns
module ClassMethods
def model_type_column(**options = {})
column(:model-type,
html: true,
class: 'table__column--type',
order: QueryHelpers::Order.by_field(:first_column),
order_desc: QueryHelpers::Order.by_field(:first_column, :desc),
** options
) do
....
end
def another_column(**options ={})
column(:another_column, :complex_logic, **options)
end
end
And then, your shared code can be used in flexile way
class FirstGrid
include Datagrid
include SharedColumns
model_type_column
column(:id)
another_column(custom_options)
end
I consider such solution superior to the idea that column order is decoupled from columns definition.
Wow! Thanks for the idea! Looks nice.
Hello! I have some datagrids sharing the same columns. These columns are pretty complex and I decided to extract them to a module to reduce code duplication. But I need these columns to be rendered in a different order in different datagrids. Here is an example.
I expected to have DSL like this:
Is there are a solution to my problem in datagrid gem? Searching in issues and googling did not give me anything.