Class: AdminSuite::Renderers::TableFromRenderer

Inherits:
AdminSuite::Renderer show all
Defined in:
lib/admin_suite/renderers/table_from_renderer.rb

Overview

Table panel over an Array of Hashes. Columns default to the first row's keys.

Instance Attribute Summary

Attributes inherited from AdminSuite::Renderer

#options, #record, #view

Instance Method Summary collapse

Methods inherited from AdminSuite::Renderer

#initialize

Constructor Details

This class inherits a constructor from AdminSuite::Renderer

Instance Method Details

#renderObject



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/admin_suite/renderers/table_from_renderer.rb', line 7

def render
  rows = source_value([]) || []
  # A Hash source is the contract violation worth naming; other
  # Enumerables (AR relations, Sets, ...) coerce cleanly via #to_a and
  # were supported before this guard existed — don't narrow that away.
  rows = rows.to_a if !rows.is_a?(Array) && !rows.is_a?(Hash) && rows.respond_to?(:to_a)
  unless rows.is_a?(Array)
    raise ArgumentError, "table_from expects an Array of Hashes, got #{rows.class}"
  end

  columns = options[:columns].presence || rows.first&.keys || []
  data_table(rows, columns: columns.map(&:to_sym), empty: options[:empty])
end