
Security News
Django Joins curl in Pushing Back on AI Slop Security Reports
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
Provides powerful set of functionality for showing tables of data:
Requires and works only with Ransack, Kaminari, Bootstrap CSS, Rails, simple_form and Turbo gems.
rails generate custom_table install
to create User migration and Initializer@import 'custom_table/table.css';
The most important part of using this gem is to correctly declare fields available for showing in table.
This should be declared in helper named by this pattern:
{singular_model_name}_custom_table_fields
And shold return hash of field definitions:
e.g.
def vegetable_custom_table_fields
fields = {}
fields[:color] = { search: { q: :color_eq, type: :text }, appear: :default }
return fields
end
Use attribute name as key if possbile. Table will try to get most of options automatically from model if you pass regular attribute.
label
adds label to the field. Will try to find human attribute name by defaultsearch
contains search parameters. Skip this if search is not available for this fieldsq
ransack's "q" search marcher which is used to search by the field. For range use array of two elements, e.g. [:created_at_gteq, :created_at_lteq]
type
type of search element to drawsm_visible
set to true to make this field search always be visible in small screens (by default all fields collapsed)appear
controls visibility of the field. Default value is hidden if not specially selecteddefault
will appear by defaultalways
will always appearexport
will appear only in XLSX exportlink_to_show
if true, this fields will have link to show page of itemsort
controls sorting ability for the fields (disabled by default). Use true
or {default_order: :asc|:desc}
amount
if true, applies number-specific formatting to cells (right align)helper
helper name (will be used instead default, see below)total_scope
scope which will be applied to collection to count total for rows. By defalt it takes sum(:field)Add CustomTableConcern
to your controller to get easy index page solution.
This gem provides custom_table method for your controller which does Ransack search and Kaminari pagination for you:
def index
@q = @vegetables.ransack(params[:q])
@q.sorts = 'created_at desc' if @q.sorts.empty? # Sets default sorting for ransack
@vegetables = @q.result(distict: true)
@vegetables = @vegetables.page(params[:page]).per(params[:per] || 25)
end
Is equivalent to:
def index
@vegetables = custom_table(@vegetables)
end
Optional parameters are:
default_sorts
- string
sorting order if user not selected it (default to created_at desc
)default_query
- default ransack q
object. Default is emptyInvoke this in your index to display table:
custom_table_data collection: @vegetables
Options available are:
collection
is the only required option. Contains paged collection from your controllerparent
parent resource for inherited routesskip_fields
array of field names as symbols. Removes specific fields from tableskip_actions
removes all actionsskip_default_actions
removes default actionsactions
helper name for custom actions. Table also looks for {singular_model_name}_custom_table_actions
helper presencetotals
object of fields to show totals. Use symbols as keys and pass value or left nil to let table try to count total based on raw/field valuepaginate
set to false to skip paginationlast_page
set to false to disable last page count request for performancequick_filter
set to true to enable simple full-text client-side searchwith_select
allows to add checkboxes toggler. Pass helper name which has (item, position) as parameterstree
set to true if you have parent-child relation and you want to show records grouped by parent. Be sure to disable pagination as it will only group current page recordsgroup_by
set to helper name to group records by result of it. Be sure to disable pagination as it will only group current page recordsexpanded
expand grouped or trees by defaultsortable
set to true to allow to sort models. Model needs to have position
attribute and use acts_as_list
gem to be sorted. Gem uses stimulus-sortable
JS package for sortingUse this helper in order to show filter panel:
custom_table_filter search_model: Vegetable
Options:
search_model
model class to use with this filter. The only required parameter.hide_customization
hides customization buttonfields
if you want to have pre-defined fields, not from model definitionYou can declare fields which your model doesn't have. In this case table can't render field value so you have to provide helpers for rendering the field. Table renderer will try to look for these helpers in prioritizing order:
#{singular_model_name}_#{field}_field
to avoid naming collisions#{singular_model_name}_#{field}
best choise for most projects#{singular_model_name}_#{field}_raw
use this to produce non-decorated raw data which can be used in tablesIf helper is not accessible table will try to render item via following methods:
to_s
methodamount
helper which formats numberboolean_icon
helper. Uses bootstrap icons and can be overridenIf you use variant, following helper will have the priority over all options:
#{singular_model_name}_#{variant}_#{field}_field
#{singular_model_name}_#{variant}_#{field}
Add CustomTable as engine to your routes:
And custom_table
attribute as text to your model
Search Settings button will show up automatically if you have at least one customizable field.
You can also use settings button separatelly. It uses Rails turbo and you need to declare turbo-modal
Turbo Tag within your HTML body.
For each table you can declare additional variants (set of parameters to be saved to user customization).
Important to note that you need to explicitly set list of available variants. Declare the following helper function:
{singular_model_name}_custom_table_fields
Which returns the array of available variant.
Then just pass variant to filter and data helpers.
You can set batch
option to field definition to enable batch editing
You need to set following options to custom_table_data
:
batch_actions
- shows batch actions. Set to helper name for custom actionsbatch_activator
- shows more compact batch selecting view. Enabled by defaultYou have to declare the following routes for the resource:
batch_edit
- POST with plural model name
array will be requested to show form for mass editingbatch_update
- POST with plural model name
array will be requested to update records with paramsbatch_destroy
- DELETE with plural model name
array will be requested to delete recordsThis gem also provide partial for exporting all available columns as XLSX file via CAXLSX gem:
wb = xlsx_package.workbook
wb.add_worksheet(name: "Aircrafts") do |sheet|
render 'custom_table/table', sheet: sheet, collection: @aircrafts.except(:limit, :offset)
end
You can use the same fields declared for table within show views. This also can be used without any table fields declaration and setup.
The simpliest case here is (haml):
= fieldset @instance do |fs|
= fs.field :name
It will produce bootstrap fieldset formatting as well as value logic from tables.
Fieldset formatting can be overriden via views (custom_table/_fieldset and custom_table/field)
By default fieldset is integrated with turbo_editable
gem and each field is wrapped with it. You can disable it by passing editable: false
as param to fieldset of field.
Options available are:
label
- if it cannot be received via field definitioneditable_params
- hash of params to be passed to editableAll options from fieldset are proxied to field. So you can declare it once if suitable.
You can declare how each field is displayed. Just add it as block within field:
= fieldset @instance do |fs|
= fs.field :name do
= @instance.name.upcase
Use custom_table_use_all_fields
GET param with any value to show all available fields in your feature tests
Running tests:
bundle install
bundle exec rails db:migrate
RAILS_ENV=test bundle exec rspec
FAQs
Unknown package
We found that custom_table demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.