Class: AjaxDatatablesRails::AltApi::Datatable::ColumnDef
- Inherits:
-
Object
- Object
- AjaxDatatablesRails::AltApi::Datatable::ColumnDef
- Defined in:
- lib/ajax-datatables-rails/alt-api/datatable/column_def.rb
Overview
This is a datatable column definition
Constant Summary collapse
- ColumnDefError =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#attr_name ⇒ Object
readonly
Returns the value of attribute attr_name.
-
#cell_renderer ⇒ Object
readonly
Returns the value of attribute cell_renderer.
-
#cond ⇒ Object
readonly
Returns the value of attribute cond.
-
#condition ⇒ Object
readonly
Returns the value of attribute condition.
-
#datatable ⇒ Object
Returns the value of attribute datatable.
-
#search_only ⇒ Object
readonly
Returns the value of attribute search_only.
-
#searchable ⇒ Object
readonly
Returns the value of attribute searchable.
-
#sortable ⇒ Object
readonly
Returns the value of attribute sortable.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#visible ⇒ Object
readonly
Returns the value of attribute visible.
Instance Method Summary collapse
-
#as_json ⇒ Object
Used to serialize options passed to the JS datatable initializer columns.
-
#initialize(attr_name, source: nil, sortable: true, visible: true, searchable: true, condition: nil, cond: :like, search_only: false, display_only: false, &cell_renderer) ⇒ ColumnDef
constructor
rubocop:disable Metrics/ParameterLists,Metrics/AbcSize.
-
#render(row_context) ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/MethodLength.
- #render? ⇒ Boolean
- #view_column ⇒ Object
Constructor Details
#initialize(attr_name, source: nil, sortable: true, visible: true, searchable: true, condition: nil, cond: :like, search_only: false, display_only: false, &cell_renderer) ⇒ ColumnDef
rubocop:disable Metrics/ParameterLists,Metrics/AbcSize
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ajax-datatables-rails/alt-api/datatable/column_def.rb', line 14 def initialize(attr_name, # rubocop:disable Metrics/ParameterLists,Metrics/AbcSize source: nil, sortable: true, visible: true, searchable: true, condition: nil, cond: :like, search_only: false, display_only: false, &cell_renderer) @attr_name = attr_name @source = source if display_only visible = true searchable = false sortable = false end if search_only visible = false searchable = true sortable = false end @condition = condition @visible = visible @sortable = visible ? sortable : false @cell_renderer = cell_renderer @searchable = searchable @search_only = search_only @cond = cond @datatable = nil end |
Instance Attribute Details
#attr_name ⇒ Object (readonly)
Returns the value of attribute attr_name.
10 11 12 |
# File 'lib/ajax-datatables-rails/alt-api/datatable/column_def.rb', line 10 def attr_name @attr_name end |
#cell_renderer ⇒ Object (readonly)
Returns the value of attribute cell_renderer.
10 11 12 |
# File 'lib/ajax-datatables-rails/alt-api/datatable/column_def.rb', line 10 def cell_renderer @cell_renderer end |
#cond ⇒ Object (readonly)
Returns the value of attribute cond.
10 11 12 |
# File 'lib/ajax-datatables-rails/alt-api/datatable/column_def.rb', line 10 def cond @cond end |
#condition ⇒ Object (readonly)
Returns the value of attribute condition.
10 11 12 |
# File 'lib/ajax-datatables-rails/alt-api/datatable/column_def.rb', line 10 def condition @condition end |
#datatable ⇒ Object
Returns the value of attribute datatable.
12 13 14 |
# File 'lib/ajax-datatables-rails/alt-api/datatable/column_def.rb', line 12 def datatable @datatable end |
#search_only ⇒ Object (readonly)
Returns the value of attribute search_only.
10 11 12 |
# File 'lib/ajax-datatables-rails/alt-api/datatable/column_def.rb', line 10 def search_only @search_only end |
#searchable ⇒ Object (readonly)
Returns the value of attribute searchable.
10 11 12 |
# File 'lib/ajax-datatables-rails/alt-api/datatable/column_def.rb', line 10 def searchable @searchable end |
#sortable ⇒ Object (readonly)
Returns the value of attribute sortable.
10 11 12 |
# File 'lib/ajax-datatables-rails/alt-api/datatable/column_def.rb', line 10 def sortable @sortable end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
10 11 12 |
# File 'lib/ajax-datatables-rails/alt-api/datatable/column_def.rb', line 10 def source @source end |
#visible ⇒ Object (readonly)
Returns the value of attribute visible.
10 11 12 |
# File 'lib/ajax-datatables-rails/alt-api/datatable/column_def.rb', line 10 def visible @visible end |
Instance Method Details
#as_json ⇒ Object
Used to serialize options passed to the JS datatable initializer columns
47 48 49 |
# File 'lib/ajax-datatables-rails/alt-api/datatable/column_def.rb', line 47 def as_json { data: attr_name, visible: visible, sortable: sortable } if condition_met? end |
#render(row_context) ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/MethodLength
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/ajax-datatables-rails/alt-api/datatable/column_def.rb', line 62 def render(row_context) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength return unless render? record = row_context.record if cell_renderer if cell_renderer.arity == 1 row_context.instance_exec(record, &cell_renderer) else row_context.instance_exec(&cell_renderer) end elsif record.respond_to?(attr_name) record.send(attr_name) else raise ColumnDefError, "Unable to render #{attr_name} for datatable: #{datatable.class.name}" end end |
#render? ⇒ Boolean
58 59 60 |
# File 'lib/ajax-datatables-rails/alt-api/datatable/column_def.rb', line 58 def render? visible && condition_met? end |
#view_column ⇒ Object
51 52 53 54 55 56 |
# File 'lib/ajax-datatables-rails/alt-api/datatable/column_def.rb', line 51 def view_column { source: search_source, orderable: to_bool(sortable), searchable: to_bool(searchable), cond: cond } end |