Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add sorting_field to Field #2659

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

goosys
Copy link

@goosys goosys commented Sep 13, 2024

I've split the Sortable from #2658.

Usage

  • It is possible to use a name as attribute_name that doesn't exist in the DB column but is defined in the model.

image

class Order < ApplicationRecord
  def address
    [address_line_two, address_line_one, address_city, address_state, address_zip].compact.join(" ")
  end
end

class OrderDashboard < Administrate::BaseDashboard
  ATTRIBUTE_TYPES = {
    address_line_one: Field::String,
    address_line_two: Field::String,
    address_city: Field::String,
    address_state: Field::String,
    address_zip: Field::String,
    address: Field::String.with_options(
      # Field used for sorting
      sorting_field: :address_zip,
      # Virtual fields cannot be searchable, so 'false' must be specified
      searchable: false
    ),
  • Attributes that cannot be sorted will not have a sort link in the table header.
module Administrate
  module Field
    class Password < Field::Base
      def self.sortable?
        false
      end
class CustomerDashboard < Administrate::BaseDashboard
  ATTRIBUTE_TYPES = {
    # Since the aggregation is done on the Ruby side and sorting is not possible, it is set to not be sortable.
    lifetime_value: Field::Number.with_options(prefix: "$", decimals: 2, sortable: false),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant