ActionTabler provides a drop in table action for your Rails controllers using DataTables.
Add to your Gemfile:
Install the gem:
//= require action_tabler
Include the datatables css in application.css
*= require action_tabler
Once you've installed ActionTabler, you can add a fully functional table page to a resource.
Define a table-enabled resourceful route for your controller:
Add a declaration to your_thing_controller.rb:
has_table_action :created_at, :title
Start your server and navigate to "your_thing/table"
The following options can be configured with a Rails initializer:
action_tabler_columns: Array of column specifications. See complete documentation below. Default is nil.
action_tabler_table_class: Table html class. Default is nil.
action_tabler_auto_width: Datatables auto width setting. Default is true.
action_tabler_action: The controller action name for a table. Default is "table".
action_tabler_auto_type: Automatically populate datatables column types based on Rails column introspection. Default is true.
action_tabler_pass_params: Use request paramters associated with the table resource (eg. "[customers]last_name=Smith") to pre-filter the table data. Default is false, in a trade off of less magic for more security.
action_tabler_table_options: Additional DataTables table options, features and callbacks. See the has_table_action :table_options documentation below. Default is empty.
All of these options can be overridden by the
has_table_action declaration will add a table display action to a controller.
The column parameter describes what will be displayed in your table.
It is either an array or the symbol
When :auto, ActionTabler will use reflection to display all of the resource's columns in the table it generates. Use of this option is strong discouraged, but can be used to just make somthing happen, even if it happens insecurely.
An array will define a list of columns to display.
A string or symbol in an array will add the corresponding model attribute or method using the default column options.
You can customize a particular column's options by passing a hash. Each hash can or should have the values below (DataTables equivalents are given in parenthases):
name: The attribute name. This can be a relationship attribute. For example, if you have an order which belongs to a customer which has a name attribute, you can specify "customer.name". (
label: The table column heading for this attribute. Default is the attribute name will be titleized. (
searchable: Include this column in search box calls. Default is true. (
sortable: Provide sort controls for this column. Default is true. (
Options not listed above will be passed through to DataTables, so that you can access options like
sVisible. For the special handling of the sType column, see the
:auto_type option below. For more on the special handling of DataTables
m options see the "Datatables fn and m Options" below.
You can learn more about DataTable column options in the DataTables Column Usage documentation.
This parameter can either be passed as the first argument or as a block. For example:
has_table_action [:first_name, :last_name], :pass_params => true
has_table_action(:pass_params => true) do column :title column :author, column :created_at, :label => "Entered", :searchable => false end
Unless specified otherwise in your Rails configuration, ActionTabler assigns it's table display method to a method called "table." You can override this with the action option, with something like "index," for example.
Specify whether to populate your column definitions with DataTable's data types using Rails reflections. This will not override any sType speficications you manually configure. Default is true unless otherwise configured.
Specifies whether to use paramters associated with the table resource to pre-filter the table data.
ActionTabler likes resourceful routes, so it will guess the model from the controller name. You can override this with the class_name option.
This specifies the html class(es) for your table.
You can specify a hash of additional DataTables options, features and callbacks. This will be added to or override your action_tabler_table_options configuration. See "Datatables fn and m Options" below for more on the special handling of DataTables
m options. Please note: you cannot override overriding such options as
fnServerParams could have unintended consequences.
- String: a string which will be evaluated as is;
- Symbol: the name of a helper method which will be executed with a single argument containing the current column definition hash; or,
- Proc: a Proc which will passed the current column definition hash.
$ bundle install $ rspec spec
Copyright (c) 2013 Larry Halff, released under the MIT license