RailsPivotTableJs
The rails_pivot_table_js
is a Rails gem that provides a helper to display a PivotTable.js (http://nicolas.kruchten.com/pivottable/examples/) in your Rails application.
PivotTable.js is Javascript Pivot Table (aka Pivot Grid, Pivot Chart, Cross-Tab) implementation with drag'n'drop and many other functionalities.
Features
- Encaplsulates all pivottable.js scripts and css
- provide a helper to display the pivot_table
- TODO: Saved Configs, scoped by contexts, to persist pivot configurations for later retrieval
Installation
Add this line to your application's Gemfile:
gem 'rails_pivot_table_js'
Execute:
$ bundle
Or install it yourself as:
$ gem install rails_pivot_table_js
Usage
First, in your model, genrate the desired data as annra of hashes, then convert it to JSON
def pivot_data
rows = []
self.documentos.each do |nfe|
rows << {
'Emitente' => nfe.estabelecimento.nome,
'Emitente CNPJ' => nfe.estabelecimento.cnpj,
'Mês Emissão' => nfe.nf_data_emissao.strftime('%y-%m'),
'Valor' => nfe.nf_valor
}
end
rows.to_json
end
In your controoler, define the data and defaul_config
@pivot_dara = cliente.pivot_data
@pivot_columns = {
cols: ['Emitente'],
rows: ['Mês Emissão']
}
In yout view, call the helper with the data
%hr
%h3 Indicadores de Documentos Recebidos
= show_pivot_table @pivot_data, @pivot_columns
All done! Enjoy the pivot table!
i18n Support
translation to portuguese is provided by the pivot.pt.js
Contributing
- Fork it ( https://github.com/davidbrusius/ransack_advanced_search/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
This project uses MIT-LICENSE.