Ransack Table

Needle has *no* chance in this haystack
Includes a Ruby component and corresponding Rails helper
Ruby
This is a paid-only premium component
Premium

Built 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
Wreckfest Bugbear Entertainment Multi 2018 View
F1 23 Codemasters Multi 2023 View
Dirt Rally Codemasters Multi 2015 View
Burnout Paradise Criterion Games Multi 2008 View
Need for Speed Heat Ghost Games Multi 2019 View
iRacing iRacing.com PC 2008 View
Assetto Corsa Kunos Simulazioni PC 2014 View
Hot Wheels Unleashed Milestone Multi 2021 View
TrackMania Nadeo PC 2020 View
Ridge Racer Namco Arcade 1993 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

Premium

Set up Nitro Kit then

bin/rails app:template \
  LOCATION="https://nitrokit.dev/t/premium/ransack_table?license=LICENSE-KEY"

Dependencies

This component adds third-party dependencies:

Usage

nk_search_form_for(record, **options) { |f| ... }
PropertyDefaultDescription
recordRansack search object The Ransack search object, typically created with Model.ransack(params[:q]).
**attrsHTML attributes for <form> element
nk_ransack_table(record, **attrs) { |t| ... }
PropertyDefaultDescription
recordRansack search object The same Ransack search object used with the search form.
**attrsHTML attributes for <table> element
table.sortable_th(attribute, label = nil, **attrs) { ... }
PropertyDefaultDescription
attributeSymbol The model attribute to sort by (e.g., :name, :created_at).
labelString 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_indicatorBoolean Whether to hide the sort direction indicator arrows.
**attrsHTML 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