Closed rusikf closed 7 years ago
As I understand you want to disable order for entire grid not for particular columns. Both things are possible.
Disable for entire grid pass order: false
into the datagrid_table
.
Disable particular columns on particular action:
class Grid
attr_accessor :disable_order
def self.controlled_order
proc { |grid|
!grid.disable_order && yield
}
end
column(:a, order: "column1") # column where order is always enabled.
column(:b, order: controlled_order { "column2" })
column(:c, order: controlled_order { "column3" })
end
# In controller
@grid = Grid.new(params[:grid].merge(disable_order: true)
@bogdan thank's for answer, but no, in your example !disable_order
is executed in class context, I checked it
If I try proc {|grid| !disabled }
, so in this case disable_order is nill because this all block evaluated in class context before instance has been initialized
What about proc {|grid| !grid.disabled }
?
I tried it , but doesn't works. |grid| in this context has not assigned disabled property yet
True, lets try a different plan:
attr_accessor :restrict_order
column(:b, order: "whatever", restricted_order: true)
Run rake datagrid:copy_partials
and modify app/views/datagird/_order_for.html.erb
like this:
+ <% if !column.options[:restricted_order] || !grid.restrict_order %>
<div class="order">
<%= link_to(
I18n.t("datagrid.table.order.asc").html_safe,
url_for(grid.param_name => grid.as_query.merge(:order => column.name, :descending => false)),
:class => "asc") %>
<%= link_to(
I18n.t("datagrid.table.order.desc").html_safe,
url_for(grid.param_name => grid.as_query.merge(:order => column.name, :descending => true )),
:class => "desc") %>
</div>
+ <% end %>
Same recommendations to control order from controller.
no, this hardcoding is not a best idea, I don't want to change views in this case :smile_cat:
I don't envision this as a hardcode: you add your own option to columns. Why would it be hardcode? What are other reasoning behind that?
Hello, how to disable order per instance ? For example, for the same grid at one action I want to disable order, for another - to enable. It looks that in wiki there is only way to disable it per class, not per instance.( If we set order: false for column - false is evaluated per class, if use proc, it is used for scope, not for disable/enable )