app/datatables/olivander/datatable.rb in five-two-nw-olivander-0.1.2.25 vs app/datatables/olivander/datatable.rb in five-two-nw-olivander-0.1.2.26

- old
+ new

@@ -16,23 +16,30 @@ end def self.auto_datatable(klazz, collection: nil, link_path: nil, only: [], except: [], hide: [], show: [], order_by: []) Rails.logger.debug "initializing datatable for #{klazz}" - attributes = klazz.new.attributes.collect{ |x| x[0] } - attributes &&= only if only.size.positive? - attributes -= except if except.size.positive? + klazz_attributes = klazz.new.attributes.collect{ |x| x[0] } + column_attributes = klazz_attributes + column_attributes &&= only if only.size.positive? + column_attributes -= except if except.size.positive? default_hidden = %w[id created updated created_at updated_at deleted_at current_user current_action] collection do - collection.nil? ? klazz.all : collection + dc = collection.nil? ? klazz.all : collection + + attributes.each do |att| + dc = dc.where("#{att[0]} = ?", att[1]) if klazz_attributes.include?(att[0].to_s) + end + + dc end datatable do order(order_by[0], order_by[1]) if order_by.size == 2 bulk_actions_col - attributes.each do |key| + column_attributes.each do |key| label = field_label_for(klazz, key) sym = key.gsub('_id', '').to_sym visible = show.include?(key) || !(default_hidden.include?(key) || hide.include?(key)) if link_path.present? && sym == :id link_col sym, link_path, :id, visible: visible