Sha256: 8249417ec6350a0a1ae4d143ca28891b07041725f2a548a8b176abece54660da

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

module Datagrid
  module ColumnNamesAttribute
    extend ActiveSupport::Concern

    included do
      class_attribute :columns_array
      self.columns_array = []

      datagrid_attribute :column_names do |names|
        names = Array(names).reject(&:blank?)
        if names.reject(&:blank?).blank?
          columns.map(&:name)
        else
          names
        end
      end
    end

    module ClassMethods
      # Adds a filter that acts like a column selection
      def column_names_filter
        filter(:column_names, :enum, :select => proc { |grid| grid.class.columns.map {|c| [c.header, c.name] }}, :multiple => true ) do |value|
          scoped
        end
      end
    end

    def columns(*args) #:nodoc:
      options = args.extract_options!
      column_names = selected_column_names(*args)
      column_names << options
      super(*column_names)
    end

    protected

    def selected_column_names(*args)
      if args.any?
        args.compact!
        args.map!(&:to_sym)
        args
      else
        column_names ? column_names.clone : []
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
datagrid-0.9.3 lib/datagrid/column_names_attribute.rb
datagrid-0.9.2 lib/datagrid/column_names_attribute.rb