rails-tables 0.6.2 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -12,7 +12,7 @@ A clean jQuery datatables DSL
12
12
  [jqd-railscast]: http://railscasts.com/episodes/340-datatables (Episode #340: Datatables)
13
13
  [squeel]: https://github.com/ernie/squeel (Squeel: ActiveRecord 3, improved)
14
14
 
15
- Version: 0.6.2
15
+ Version: 0.6.3
16
16
 
17
17
  Please refer to the [RailsTables Wiki][wiki] for:
18
18
 
@@ -5,11 +5,7 @@ $ ->
5
5
  $(@).data('unsorted', true)
6
6
 
7
7
  @rails_tables = {}
8
- @rails_tables.columns = ->
9
- for column, order of $(@).data() when /_ordering/.test(column)
10
- asSorting: [ order ], aTargets: [ column.substring(0, column.length - "_ordering".length) ]
11
-
12
- @rails_tables.params = (aoData) ->
13
- aoData.push
14
- name: 'bUseDefaultSort', value: if $(@).data('unsorted') then true else false
15
-
8
+ @rails_tables.params = (datatable) ->
9
+ (aoData) ->
10
+ aoData.push
11
+ name: 'bUseDefaultSort', value: if $(datatable).data('unsorted') then true else false
@@ -25,11 +25,6 @@ class RailsTables::Datatable
25
25
  if self.class.source?
26
26
  options[:source] = self.class.source
27
27
  end
28
- unless self.initial_orderings.nil?
29
- self.class.initial_orderings.each do |column, order|
30
- options["#{column}_ordering".to_sym] = order.to_s
31
- end
32
- end
33
28
  options[:unsorted] = 'true'
34
29
  options
35
30
  end
@@ -53,10 +48,10 @@ class RailsTables::Datatable
53
48
  class_attribute :source, :source_factory
54
49
  # Set source url for this table
55
50
  def self.source_path=(source)
56
- self.source_factory = source
51
+ self.source_factory = source if source.present?
57
52
  end
58
53
  def self.source
59
- @source ||= Rails.application.routes.url_helpers.send(self.source_factory, format: "json")
54
+ @source ||= Rails.application.routes.url_helpers.send(self.source_factory, format: "json") if self.source_factory.present?
60
55
  end
61
56
 
62
57
  class_attribute :columns, :column_factory
@@ -2,18 +2,14 @@ module RailsTables::Sorting
2
2
  extend ActiveSupport::Concern
3
3
 
4
4
  included do
5
- class_attribute :initial_orderings
5
+ class_attribute :initial_order
6
6
  extend ClassMethods
7
7
  end
8
8
 
9
9
  module ClassMethods
10
10
  # Gotta set these to fight against datatables' default ordering on first column
11
11
  def initial_ordering(orderings)
12
- self.set_initial_orderings orderings
13
- end
14
- def set_initial_orderings(orderings)
15
- self.initial_orderings = {} if self.initial_orderings.nil?
16
- self.initial_orderings.merge! orderings
12
+ self.initial_order = orderings
17
13
  end
18
14
 
19
15
  end
@@ -22,13 +18,22 @@ module RailsTables::Sorting
22
18
  private
23
19
  # Check if table is sortable
24
20
  def sortable
25
- self.columns.map{ |column| column.sortable }[params[:iSortCol_0].to_i] unless params[:bUseDefaultSort] == 'true'
21
+ if params[:bUseDefaultSort] == 'true'
22
+ true
23
+ else
24
+ self.columns.map(&:sortable)[params[:iSortCol_0].to_i]
25
+ end
26
26
  end
27
27
  # Find column to search by and create a Squeel Order
28
28
  def sort
29
- column = self.columns[params[:iSortCol_0].to_i]
30
- if column.sortable
29
+ if params[:bUseDefaultSort] == 'true' and self.initial_order.present?
30
+ column = self.columns.select{|c|c.name == self.initial_order.keys.first.to_s}.first
31
+ direction = self.initial_order.values.first.to_s == "asc" ? 1 : -1
32
+ else
33
+ column = self.columns[params[:iSortCol_0].to_i]
31
34
  direction = params[:sSortDir_0] == "asc" ? 1 : -1
35
+ end
36
+ if column.sortable
32
37
  Squeel::Nodes::KeyPath.new(column.column_source.split('.') << Squeel::Nodes::Order.new(Squeel::Nodes::Stub.new(column.method), direction))
33
38
  end
34
39
  end
@@ -1,3 +1,3 @@
1
1
  module RailsTables
2
- VERSION = "0.6.2"
2
+ VERSION = "0.6.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-tables
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-06 00:00:00.000000000 Z
12
+ date: 2012-12-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails