app/models/effective/effective_datatable/options.rb in effective_datatables-2.9.0 vs app/models/effective/effective_datatable/options.rb in effective_datatables-2.10.0
- old
+ new
@@ -83,21 +83,16 @@
has_and_belongs_to_manys[reflect.name.to_s] = { klass: klass }
end
end
table_columns = cols.each_with_index do |(name, _), index|
- # If this is a belongs_to, add an :if clause specifying a collection scope if
- if belong_tos.key?(name)
- cols[name][:if] ||= Proc.new { attributes[belong_tos[name][:foreign_key]].blank? }
- end
-
sql_column = (collection.columns rescue []).find do |column|
column.name == name.to_s || (belong_tos.key?(name) && column.name == belong_tos[name][:foreign_key])
end
cols[name][:array_column] ||= false
- cols[name][:array_index] = index # The index of this column in the collection, regardless of hidden table_columns
+ cols[name][:index] = index # The index of this column in the collection, regardless of hidden table_columns
cols[name][:name] ||= name
cols[name][:label] ||= name.titleize
cols[name][:column] ||= (sql_table && sql_column) ? "#{quote_sql(sql_table.name)}.#{quote_sql(sql_column.name)}" : name
cols[name][:width] ||= nil
cols[name][:sortable] = true if cols[name][:sortable].nil?
@@ -161,23 +156,10 @@
if cols[name][:partial]
cols[name][:partial_local] ||= (sql_table.try(:name) || cols[name][:partial].split('/').last(2).first.presence || 'obj').singularize.to_sym
end
end
- # After everything is initialized
- # Compute any col[:if] and assign an index
- count = 0
- table_columns.each do |name, col|
- if display_column?(col)
- col[:index] = count
- count += 1
- else
- # deleting rather than using `table_columns.select` above in order to maintain
- # this hash as a type of HashWithIndifferentAccess
- table_columns.delete(name)
- end
- end
end
def initialize_table_column_filter(column, belongs_to, has_many, has_and_belongs_to_manys)
filter = column[:filter]
col_type = column[:type]
@@ -277,17 +259,8 @@
else
{as: :string}
end.merge(filter.symbolize_keys)
end
- private
-
- def display_column?(col)
- if col[:if].respond_to?(:call)
- (view || self).instance_exec(&col[:if])
- else
- col.fetch(:if, true)
- end
- end
end
end
end