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

Add sorting_column to Field #2659

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

goosys
Copy link
Contributor

@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 OrderDashboard < Administrate::BaseDashboard
  ATTRIBUTE_TYPES = {
    full_address: Field::String.with_options(
      getter: ->(field) {
        r = field.resource
        [
          r.address_line_one,
          r.address_line_two,
          r.address_city,
          r.address_state,
          r.address_zip
        ].compact.join("\n")
      },
      sorting_column: :address_zip
    ),
  • 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),

@goosys goosys changed the title WIP: Add sorting_field to Field WIP: Add sorting_column to Field Oct 29, 2024
@goosys goosys changed the title WIP: Add sorting_column to Field Add sorting_column to Field Oct 29, 2024
@goosys
Copy link
Contributor Author

goosys commented Oct 29, 2024

I rebased after #2658 was merged and made a few additional fixes.

@goosys
Copy link
Contributor Author

goosys commented Oct 29, 2024

I feel that we need to discuss the option name.
We already have sort_by and order options related to sorting, but the newly added option doesn’t fully serve the same purpose as either of these, though there is some overlap.
For now, I’ve named it sorting_column to avoid conflicts, but it doesn’t feel very elegant. I’d appreciate any ideas you might have.

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