Skip to content

CodiTramuntana/ct_table_for

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

71 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rails Responsive Table

Gem Version

Rails Responsive Table is a rails table builder for an ActiveRecord collection.

Optional gems

Installation

Add it to your Gemfile:

gem 'ct_table_for'

Then:

bundle

Then require the CSS in your application.css file:

/*
 *= require table_for
 */

or in sass

@import "table_for"

And require the necessary javascript in application.js if you are using the clickable row option (jQuery is required):

//= require table_for

Usage

To get started, just use the table_for helper. Here's an example:

<%= table_for Model, @collection %>

Clickable rows

To make rows clickable just add corresponding option to table_for helper:

<%= table_for Model, @collection, options: { clickable: true } %>

It builds a call to a named RESTful route for a given record from a collection. Also, you can specify your own nested resources path by passing an array of symbols:

<%= table_for Model, @collection, options: { clickable: [:bo, :admin] } %>

Customizing

Create config variables in your app's /config/initializers/ct_table_for.rb

CtTableFor.setup do |config|
  config.table_for_wrapper_default_class = "table-responsive"
  config.table_for_default_class = "table table-striped table-bordered table-condensed table-hover"
  config.table_for_default_action_base_class = "btn btn-sm"
  config.table_for_action_class = {show: "btn-primary", edit: "btn-success", destroy: "btn-danger", other: "btn-default"}
  config.table_for_breakpoint = "992px" # or could be done by sass
  config.table_for_icon_font = "fa"
  config.table_for_action_icons = {show: "eye", edit: "pencil", destroy: "trash"}
  config.table_for_numeric_percentage_precision = 2
  config.table_for_cell_for_image_image_class = "img-responsive"
  config.table_for_truncate_length = 50
  config.table_for_truncate_separator = " "
  config.table_for_truncate_omission = "..."
  config.table_for_td_default_prefix_class = "td-item"
end

You can also define the breakpoint in your sass before importing table_for:

$table-for-breakpoint: 768px;
@import "table_for";

Development

To develop the Gem, clone this repo and in your Rails Test application edit the Gemfile and edit the path to your local repo:

gem 'table_for', path: '/home/user/path/to/table_for'

Contributing

Bug reports and pull requests are welcome on GitHub. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

table_for is Copyright © 2017 CodiTramuntana SL. It is free software, and may be redistributed under the terms specified in the LICENSE file.

The gem is available as open source under the terms of the MIT License.

About CodiTramuntana

CodiTramuntana's Logo

Maintained by CodiTramuntana.

The names and logos for CodiTramuntana are trademarks of CodiTramuntana SL.

We love open source software!