How to render column conditionally for ActiveAdmin `table_for` array collection

364 Views Asked by At

I have an array versions that I render on ActiveAdmin custom page (.html.arb), and I need to show some columns depending on the array element's value, but I struggle to understand how to loop over this array and apply conditional rendering

table_for versions do |element|
   ...
   column 'Example' if element == value
   ...
end

element class, in this case, is ActiveAdmin::Views::TableFor which is logical, but I can't understand how I can access versions items in this loop as their original class (Integer), so my element would be Integer too. Thanks for help in advance

2

There are 2 best solutions below

0
On

Hello implementation of table_for is not supporting it, I suggest you to create partials and pick it by name using your conditional logic instead

0
On

Using jQuery, you can hide a column. For example:

̣``` if $("td.col.col-grado").text() == "0.0".repeat($("td.col.col-grado").length) $("th.col.col-grado").hide() $("td.col.col-grado").hide() if $("td.co.col-botella").text == "" $("th.col.col-botella").hide() $("td.col.col-botella").hide()