Skip to content

Instantly share code, notes, and snippets.

@bernstein7
Created November 20, 2022 18:03
Show Gist options
  • Save bernstein7/9ef57c8f03e0400687a86cb409f1a361 to your computer and use it in GitHub Desktop.
Save bernstein7/9ef57c8f03e0400687a86cb409f1a361 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
module ActiveAdmin
class BatchTableFor < ActiveAdmin::Component
class SelectableIndexTable < ActiveAdmin::Views::TableFor
def selectable_column
column resource_selection_toggle_cell, class: "col-selectable", sortable: false do |resource|
resource_selection_cell resource
end
end
end
builder_method :batch_table_for
def default_class_name
'batch_table_for'
end
def tag_name
"div"
end
def build(collection, *attrs, &block)
@collection = collection
@table_options = {}
@table_block = block
batch_action_form do
div class: :paginated_collection do
build_batch_selector
build_table_for
end
end
end
def build_batch_selector
div class: "table_tools" do
batch_action_selector [
ActiveAdmin::BatchAction.new(:void_credits, "Void"),
]
end
end
def build_table_for
insert_tag SelectableIndexTable, @collection, @table_options, &@table_block
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment