effective_datatables 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ab3303e9840fd59709b75a87ee4b6165f44dbb2e
4
- data.tar.gz: 64908b59ab4c276098b53b98e273b246dc5262ac
3
+ metadata.gz: 21f89b360a1c91b980639a253600ceab7b73c8cc
4
+ data.tar.gz: 10a7ee6dc1d418d4cfec6a49eccd56d1484faed8
5
5
  SHA512:
6
- metadata.gz: e20d80db67245944e54982a9bd7e172aa1fbd26536ee65feb06aeda3f770a7c4b0ae6a56b0585fafeb3a4ce2989d8a4525832c4a8e1f3839496b667c70b3e3ae
7
- data.tar.gz: 856f9f5e260bb67e6d73247121f54128ff36051756d4247c8bcb7a9688f331114accc7009b41b5348f21be2ea61263e06a070dd3814e66a2fe9a5060de2f5dbb
6
+ metadata.gz: daca44eec31c3812079ea6526a5abe695c90d8a68a979cbd05115f9e6f45e8e0cac48d821ea8730d63e38799c98b2826f3ca4e71aa65a825bd126be8e49abb99
7
+ data.tar.gz: b9da26aebf979f57d86d5af428400a74589101d8e8f8ae9df805f3cbe882cb773a71b9ec153b633d2e445bb47acf6aff0550c6a798f01ef5ba1c3f637c48683a
data/README.md CHANGED
@@ -136,9 +136,7 @@ module Effective
136
136
 
137
137
  table_column :id, :visible => false
138
138
 
139
- table_column :created_at, :width => '25%' do |post|
140
- post.created_at.strftime("%Y-%m-%d %H:%M:%S")
141
- end
139
+ table_column :created_at, :width => '25%'
142
140
 
143
141
  table_column :updated_at, :proc => Proc.new { |post| nicetime(post.updated_at) } # just a standard helper as defined in helpers/application_helper.rb
144
142
 
@@ -156,7 +154,7 @@ module Effective
156
154
  end
157
155
  end
158
156
 
159
- table_column :title, :label => 'Post Title'
157
+ table_column :title, :label => 'Post Title', :class => 'col-title'
160
158
  table_column :actions, :sortable => false, :filter => false, :partial => '/posts/actions'
161
159
 
162
160
  def collection
@@ -265,6 +263,7 @@ The following options control the display behaviour of the column:
265
263
  :sortable => true|false # Allow sorting of this column. Otherwise the up/down arrows on the frontend will be disabled.
266
264
  :visible => true|false # Hide this column at startup. Column visbility can be changed on the frontend. By default, hidden column filter terms are ignored.
267
265
  :width => '100%'|'100px' # Set the width of this column. Can be set on one, all or some of the columns. If using percentages, should never add upto more than 100%
266
+ :class => 'col-example' # Adds an html class to the column's TH and all TD elements. Add more than one class with 'example col-example something'
268
267
  ```
269
268
 
270
269
  ### Filtering Options
@@ -3,6 +3,11 @@ initializeDataTables = ->
3
3
  unless $.fn.DataTable.fnIsDataTable(this)
4
4
  datatable = $(this)
5
5
 
6
+ aoColumnDefs = [
7
+ { bSortable: false, aTargets: datatable.data('non-sortable') },
8
+ { bVisible: false, aTargets: datatable.data('non-visible') }
9
+ ].concat(datatable.data('column-classes') || [])
10
+
6
11
  init_options =
7
12
  bServerSide: true
8
13
  bProcessing: true
@@ -17,17 +22,7 @@ initializeDataTables = ->
17
22
  table = this.DataTable()
18
23
  table.columns().flatten().each (index) ->
19
24
  aoData.push({'name': "sVisible_#{index}", 'value': table.column(index).visible()})
20
- aoColumnDefs:
21
- [
22
- {
23
- bSortable: false,
24
- aTargets: datatable.data('non-sortable')
25
- },
26
- {
27
- bVisible: false,
28
- aTargets: datatable.data('non-visible')
29
- }
30
- ]
25
+ aoColumnDefs: aoColumnDefs
31
26
  aoColumns: datatable.data('widths')
32
27
  oTableTools:
33
28
  sSwfPath: '/assets/effective_datatables/copy_csv_xls_pdf.swf',
@@ -62,6 +62,14 @@ module EffectiveDatatablesHelper
62
62
  datatable.table_columns.values.map { |options| {'sWidth' => options[:width]} if options[:width] }.to_json()
63
63
  end
64
64
 
65
+ def datatable_column_classes(datatable)
66
+ [].tap do |classes|
67
+ datatable.table_columns.values.each_with_index do |options, x|
68
+ classes << {:className => options[:class], :targets => [x]} if options[:class].present?
69
+ end
70
+ end.to_json()
71
+ end
72
+
65
73
  def datatables_admin_path?
66
74
  (attributes[:admin_path] || request.referer.downcase.include?('/admin/')) rescue false
67
75
  end
@@ -315,6 +315,8 @@ module Effective
315
315
  cols[name][:width] ||= nil
316
316
  cols[name][:sortable] = true if cols[name][:sortable] == nil
317
317
  cols[name][:type] ||= (belong_tos.key?(name) ? :belongs_to : (sql_column.try(:type).presence || :string))
318
+ cols[name][:class] = "col-#{cols[name][:type]} #{cols[name][:class]}".strip
319
+ cols[name][:class] << ' col-actions' if name == 'actions'
318
320
 
319
321
  if name == 'id' && collection.respond_to?(:deobfuscate)
320
322
  cols[name][:sortable] = false
@@ -1,4 +1,4 @@
1
- %table.effective-datatable{:id => "#{datatable.to_param}-table", :class => ('table ' + table_class.to_s), :data => {'effective-datatables-table' => style, 'source' => effective_datatables.datatable_path(datatable, {:format => 'json'}.merge(:attributes => datatable.attributes)), 'filter' => datatable_filter(datatable, filterable), 'non-sortable' => datatable_non_sortable(datatable, sortable), 'non-visible' => datatable_non_visible(datatable), 'widths' => datatable_widths(datatable), 'default-order' => datatable_default_order(datatable)}}
1
+ %table.effective-datatable{:id => "#{datatable.to_param}-table", :class => ('table ' + table_class.to_s), :data => {'effective-datatables-table' => style, 'source' => effective_datatables.datatable_path(datatable, {:format => 'json'}.merge(:attributes => datatable.attributes)), 'filter' => datatable_filter(datatable, filterable), 'non-sortable' => datatable_non_sortable(datatable, sortable), 'non-visible' => datatable_non_visible(datatable), 'widths' => datatable_widths(datatable), 'default-order' => datatable_default_order(datatable), 'column-classes' => datatable_column_classes(datatable)}}
2
2
  %thead
3
3
  - max_depth = datatable.table_columns.map { |_, opts| opts[:th][:depth].to_i rescue 0 }.max
4
4
  - [*0..max_depth].each do |depth|
@@ -1,3 +1,3 @@
1
1
  module EffectiveDatatables
2
- VERSION = '1.0.3'.freeze
2
+ VERSION = '1.1.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_datatables
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-31 00:00:00.000000000 Z
11
+ date: 2015-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails