I am trying to generate the columns of my table with data coming from a table that stores the order of each column that was created when the user rearrange the columns.
E.g in my property_grid.rb file I am trying to generate the columns using this array ["Attribute 1", "Attribute 2", "Attribute 3"]
.
["Attribute 1", "Attribute 2", "Attribute 3"].each do |v|
case v
when 'Attribute 1'
column(:attribute_1)
when 'Attribute 2'
column(:attribute_2)
when 'Attribute 3'
column(:attribute_3)
end
end
This works great the first time I reload the page but when the attribute array becomes ["Attribute 3", "Attribute 2", "Attribute 1"]
it doesn't change.
If I add a comment or anything else to the property_grid.rb file then it seems to work. I don't understand why it only works if I manually add something to this file. Any idea why this is happening and how can I dynamically change the position of these columns?
CodePudding user response:
you need to use map
instead of each
method. each
method returns the initial array, map
return the result of the block
CodePudding user response:
For those looking for the answer to this question refer to this https://github.com/bogdan/datagrid/issues/300#event-7064220826
All credits to @bogdan who was really helpful.