Skip to content

Resource index

Mattia Roccoberton edited this page May 16, 2023 · 5 revisions

A resource index page expose a list of items extracted using a Repository.

Here is an example (check the index key):

sections:
  - slug: posts
    name: Posts
    type: resource
    model: Post
    index:
      sort:
        - id DESC
      pagination: 10
      attributes:
        - id
        - title
        - field: author_id
          header: The author
          link_to: authors
          call: author, name
        - field: state
          method: upcase
          options: value_class
        - position: round, 1
        - created_at: strftime, %Y%m%d %H:%M
      filters:
        - title
        - field: state
          type: select
          values:
            - available
            - unavailable
            - arriving
        - published
        - author_id
      links:
        - show
        - csv_export
      widgets:
        - Admin::RankedPostsWidget

Index keys

  • sort (Array): list of sorting rules (ex. name ASC)
  • pagination (Integer): max number of records to paginate the list of items
  • attributes (Array): list of fields to expose (see below)
  • filters (Array): list of filters (see below)
  • links (Array): list of custom actions to show for each item in the list (as last column)
  • widgets (Array): list of widgets (as classes) to show at the bottom of the page

attributes

Every element of the attributes array can be:

  • a string with the field (ex. created_at)
  • a hash with a single element: field: transform_method (es. first_name: upcase)
  • a hash with more options, ex.
  - field: author_id
    header: The author
    link_to: authors
    call: author, name

filters

Every element of the filters array can be:

  • a string with the field (ex. title)
  • a hash with more options, ex.
  - field: state
    type: select
    values:
      - available
      - unavailable
      - arriving
Clone this wiki locally