The Tables system uses a declarative API accessible via
Spree.admin.tables. This allows you to programmatically add, modify, and remove table columns and bulk actions directly in your initializers.Basic Usage
Creating a New Table
Register a new table for your resource inconfig/initializers/spree.rb:
config/initializers/spree.rb
Using the Table in Views
Render the table in your index view using therender_table helper:
app/views/spree/admin/brands/index.html.erb
Table Registration Options
When registering a table, you can specify these options:The model class for the table (e.g.,
Spree::Brand).The Ransack search parameter for the search box.
Custom placeholder text for the search box.
Enable row action buttons (edit/delete dropdown).
Show edit action in row actions dropdown.
Show delete action in row actions dropdown.
Show “New Resource” button when collection is empty.
Enable date range filter for the specified column (e.g.,
:created_at).Action for link columns (
:edit or :show).Column Options
All columns support the following options:The column header label. Can be a symbol (translation key using
Spree.t) or a string.The column type. Determines how the value is rendered.Available types:
string- Plain textnumber- Numeric valuedate- Date formatted withspree_datehelperdatetime- Relative time withspree_time_agohelpermoney- Currency formatted withSpree::Moneystatus- Badge with status-based stylinglink- Clickable link to resourceboolean- Active/inactive badgeimage- Thumbnail imageassociation- Associated record name(s)custom- Custom partial rendering
Whether the column can be sorted.
Whether the column appears in the query builder filter options.
Whether the column can be shown/hidden by users. Set to
false for filter-only columns.Whether the column is visible by default.
Column order. Lower numbers appear first.
Custom method to extract the column value. Can be a method name or lambda.
Text alignment:
left, center, or right.Column width class (e.g.,
"20" for w-20).Conditional visibility. Column only appears if lambda returns true.
Filter-specific Options
Override the filter input type. Available:
string, number, date, datetime, money, status, boolean, autocomplete, select.Custom Ransack attribute name for filtering/sorting (defaults to column key).
Available filter operators. Defaults based on column type.
Options for select/status filters. Array of hashes with
value and label keys.URL for autocomplete filter type.
Custom Sort Options
Custom scope name for ascending sort (bypasses Ransack).
Custom scope name for descending sort (bypasses Ransack).
Custom Partial Options
Partial path for
custom type columns.Additional locals to pass to the partial. Lambda receives the record.
Column Types Examples
String Column
Link Column
Links to the resource edit or show page:Money Column
Displays formatted currency:Status Column
Displays a colored badge based on the status value:- Green (
badge-active):active,complete,completed,paid,shipped,available - Yellow (
badge-warning):draft,pending,processing,ready - Gray (
badge-inactive):archived,canceled,cancelled,failed,void,inactive
Boolean Column
DateTime Column
Displays relative time (e.g., “2 hours ago”):Association Column
For displaying related records:Custom Partial Column
For complex rendering:record, column, and value locals plus any custom locals.
Filter-only Column
Columns that can be filtered but not displayed:Modifying Existing Tables
Adding Columns to Existing Tables
config/initializers/spree.rb
Updating Existing Columns
Removing Columns
Inserting Columns at Specific Positions
Bulk Actions
Add bulk actions that appear when users select multiple rows:Bulk Action Options
Translation key or text for the action button.
Interpolation options for the label translation.
Icon name from Tabler Icons.
URL for the confirmation modal.
URL for the bulk action endpoint.
HTTP method for the action (
:get, :post, :put, :patch, :delete).Order in the bulk actions menu.
Conditional visibility based on user permissions.
Confirmation message before executing the action.
Managing Bulk Actions
Custom Sorting
For columns that need custom database queries:Available Tables
Spree registers tables for all built-in resources:| Table Key | Model Class |
|---|---|
:products | Spree::Product |
:orders | Spree::Order |
:checkouts | Spree::Order (draft) |
:users | Spree.user_class |
:promotions | Spree::Promotion |
:customer_returns | Spree::CustomerReturn |
:option_types | Spree::OptionType |
:newsletter_subscribers | Spree::NewsletterSubscriber |
:policies | Spree::Policy |
:stock_transfers | Spree::StockTransfer |
:metafield_definitions | Spree::MetafieldDefinition |
:gift_cards | Spree::GiftCard |
:stock_items | Spree::StockItem |
:posts | Spree::Post |
:post_categories | Spree::PostCategory |
:webhook_endpoints | Spree::WebhookEndpoint |
:webhook_deliveries | Spree::WebhookDelivery |

