Sha256: 1c432e8b3e27917454481d4f6722e8f74efd2c3ee79c22c742c2a70f7c4d4bf0

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

module ActiveAdmin
  #
  module SortableTable
    # Adds `handle_column` method to `TableFor` dsl.
    # @example on index page
    #   index do
    #     handle_column
    #     id_column
    #     # other columns...
    #   end
    #
    # @example table_for
    #   table_for c.collection_memberships do
    #     handle_column
    #     # other columns...
    #   end
    #
    module HandleColumn
      # @param [Hash] options
      # @option options [Symbol, Proc, String] :url
      #
      def handle_column(options = {})
        column '', class: 'activeadmin_sortable_table' do |resource|
          content_tag :span, '', class: 'handle', 'data-sort-url' => sort_url(options[:url], resource)
        end
      end

      private

      def sort_url(url, resource)
        if url.is_a?(Symbol)
          send(url, resource)
        elsif url.respond_to?(:call)
          url.call(resource)
        else
          sort_url, query_params = resource_path(resource).split('?', 2)
          sort_url += '/sort'
          sort_url += '?' + query_params if query_params
          sort_url
        end
      end
    end

    ::ActiveAdmin::Views::TableFor.send(:include, HandleColumn)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activeadmin_sortable_table-1.0.0 lib/active_admin/sortable_table/handle_column.rb