data_tables 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -29,11 +29,14 @@ module DataTablesHelper
29
29
  columns = datatable[:attrs].keys.collect { |a| "<th>#{a}</th>" }.join
30
30
 
31
31
  index = 0
32
+ first_searchable_column_index = nil
32
33
  targets = datatable[:attrs].inject([]) do |memo, (column, searchable)|
34
+ first_searchable_column_index ||= index if searchable
33
35
  memo << index unless searchable
34
36
  index += 1
35
37
  memo
36
38
  end
39
+ options[:aaSorting] = [[first_searchable_column_index, 'asc']]
37
40
  options[:aoColumnDefs] ||= []
38
41
  options[:aoColumnDefs].unshift({
39
42
  :aTargets => targets,
data/lib/data_tables.rb CHANGED
@@ -1,4 +1,3 @@
1
- require 'data_tables/data_tables_helper'
2
1
  module DataTablesController
3
2
  def self.included(cls)
4
3
  cls.extend(ClassMethods)
@@ -160,7 +159,9 @@ module DataTablesController
160
159
  if column.kind_of? Symbol # a column from the database, we don't need to do anything
161
160
  columns << {:name => column, :attribute => column}
162
161
  elsif column.kind_of? Hash
163
- columns << {:name => column[:name], :special => column}
162
+ col_hash = { :name => column[:name], :special => column }
163
+ col_hash[:attribute] = column[:attribute] if column[:attribute]
164
+ columns << col_hash
164
165
  end
165
166
  end
166
167
  columns
@@ -187,11 +188,7 @@ module DataTablesController
187
188
 
188
189
  # gets the value for a column and row
189
190
  def datatables_instance_get_value(instance, column)
190
- if column[:attribute]
191
- val = instance.send(column[:attribute].to_sym)
192
- return I18n.t(val.to_s.to_sym, :default => val.to_s) if not val.blank?
193
- return ''
194
- elsif column[:special]
191
+ if column[:special]
195
192
  special = column[:special]
196
193
 
197
194
  if special[:method]
@@ -200,6 +197,10 @@ module DataTablesController
200
197
  proc = lambda { obj = instance; binding }
201
198
  return Kernel.eval(special[:eval], proc.call)
202
199
  end
200
+ elsif column[:attribute]
201
+ val = instance.send(column[:attribute].to_sym)
202
+ return I18n.t(val.to_s.to_sym, :default => val.to_s) if not val.blank?
203
+ return ''
203
204
  end
204
205
  return "value not found"
205
206
  end
metadata CHANGED
@@ -1,10 +1,15 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: data_tables
3
- version: !ruby/object:Gem::Version
4
- version: 0.1.0
5
- prerelease:
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Duane Compton
9
14
  - Calvin Bascom
10
15
  - Yi Su
@@ -12,38 +17,55 @@ authors:
12
17
  autorequire:
13
18
  bindir: bin
14
19
  cert_chain: []
15
- date: 2012-10-10 00:00:00.000000000 Z
20
+
21
+ date: 2012-10-10 00:00:00 -04:00
22
+ default_executable:
16
23
  dependencies: []
24
+
17
25
  description: Originally a plugin
18
26
  email: Duane.Compton@gmail.com
19
27
  executables: []
28
+
20
29
  extensions: []
30
+
21
31
  extra_rdoc_files: []
22
- files:
32
+
33
+ files:
23
34
  - lib/data_tables.rb
24
35
  - lib/data_tables/data_tables_helper.rb
36
+ has_rdoc: true
25
37
  homepage: http://rubygems.org/gems/data_tables
26
38
  licenses: []
39
+
27
40
  post_install_message:
28
41
  rdoc_options: []
29
- require_paths:
42
+
43
+ require_paths:
30
44
  - lib
31
- required_ruby_version: !ruby/object:Gem::Requirement
45
+ required_ruby_version: !ruby/object:Gem::Requirement
32
46
  none: false
33
- requirements:
34
- - - ! '>='
35
- - !ruby/object:Gem::Version
36
- version: '0'
37
- required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ hash: 3
51
+ segments:
52
+ - 0
53
+ version: "0"
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
55
  none: false
39
- requirements:
40
- - - ! '>='
41
- - !ruby/object:Gem::Version
42
- version: '0'
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
43
63
  requirements: []
64
+
44
65
  rubyforge_project:
45
- rubygems_version: 1.8.24
66
+ rubygems_version: 1.3.7
46
67
  signing_key:
47
68
  specification_version: 3
48
69
  summary: Rails friendly interface into DataTables
49
70
  test_files: []
71
+