Ransack Table
Needle has *no* chance in this haystack
Includes a Ruby component and corresponding Rails helper
RubyThis is a paid-only premium component
PremiumBuilt to work seamlessly with the Ransack gem for advanced searching and sorting functionality. Extends the base Table component with built-in search form integration and sortable headers.
Example
Title ▲ | Studio | Platform | Year | Actions |
---|---|---|---|---|
Assetto Corsa | Kunos Simulazioni | PC | 2014 | View |
Automobilista | Reiza Studios | PC | 2016 | View |
Burnout Paradise | Criterion Games | Multi | 2008 | View |
Crash Team Racing | Naughty Dog | PlayStation | 1999 | View |
Dirt Rally | Codemasters | Multi | 2015 | View |
F1 23 | Codemasters | Multi | 2023 | View |
Forza Horizon 5 | Playground Games | Xbox/PC | 2021 | View |
F-Zero | Nintendo EAD | Nintendo | 1990 | View |
Gran Turismo 7 | Polyphony Digital | PlayStation | 2022 | View |
Hot Wheels Unleashed | Milestone | Multi | 2021 | View |
<%= nk_search_form_for @q do |f| %>
<%= f.search_field :name_cont, placeholder: "Search..." %>
<%= f.submit "Search" %>
<% end %>
<%= nk_ransack_table(@q) do |t| %>
<%= t.thead do %>
<%= t.tr do %>
<%= t.sortable_th :name, "Name" %>
<%= t.sortable_th :email, "Email" %>
<%= t.sortable_th :created_at, "Created" %>
<%= t.th "Actions" %>
<% end %>
<% end %>
<%= t.tbody do %>
<% @users.each do |user| %>
<%= t.tr do %>
<%= t.td { user.name } %>
<%= t.td { user.email } %>
<%= t.td { l(user.created_at, format: :short) } %>
<%= t.td { nk_button "Edit", size: :xs } %>
<% end %>
<% end %>
<% end %>
<% end %>
Install
PremiumSet up Nitro Kit then
bin/rails app:template \
LOCATION="https://nitrokit.dev/t/premium/ransack_table?license=LICENSE-KEY"
Usage
| ||
---|---|---|
Property | Default | Description |
record | Ransack search object |
The Ransack search object, typically created with Model.ransack(params[:q]) .
|
**attrs | HTML attributes for <form> element |
| ||
---|---|---|
Property | Default | Description |
record | Ransack search object | The same Ransack search object used with the search form. |
**attrs | HTML attributes for <table> element |
| ||
---|---|---|
Property | Default | Description |
attribute | Symbol |
The model attribute to sort by (e.g., :name , :created_at ).
|
label | String | Display text for the header. Auto-generated from attribute if not provided. |
default_order | :asc or :desc | Default sort direction when this header is first clicked. |
hide_indicator | Boolean | Whether to hide the sort direction indicator arrows. |
**attrs | HTML attributes for <th> element |
Note: Since Ransack Table is a subclass of the base Table component, it accepts all the same APIs and methods. Refer to the Table documentation for additional styling options and methods.
Controller Setup
class UsersController < ApplicationController
def index
@q = User.ransack(params[:q])
@users = @q.result.includes(:profile)
@pagy, @users = pagy(@users)
end
end