Sha256: b5be4bf446ed1695cd83140bda12c93d06ea31648571d3c83db62e44fd888ffe

Contents?: true

Size: 1.44 KB

Versions: 31

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

# Helper methods for rendering JQuery Datatables
module DatatableHelper
  def default_datatable_columns(object)
    datatable_columns(object, ['actions'] + object.column_names)
  end

  def datatable_columns(object, cols)
    obj_name = object.to_s.underscore.pluralize
    cols.map do |col|
      if col == 'actions'
        { title: '', data: "#{obj_name.tr('/', '_')}__actions",
          class: 'actions center', bSortable: false }
      else
        { title: col.split('_').collect(&:capitalize).join(' ').to_s,
          data: "#{obj_name}__#{col}", visible: true }
      end
    end
  end

  def render_datatable(object, table_url, columns: nil, table_name: nil, aoData: [], initial_size: 25, table_views: { table: true, grid: false }, table_filters: [], table_actions: nil, sort: [[0, 'asc']])
    warn("DEPRECATION WARNING: render_datatable will be removed soon (use render partial: 'partials/table' instead)")
    if table_name.nil?
      table_name = object.to_s.pluralize.underscore.tr('/', '_')
    end
    columns = default_datatable_columns(object) if columns.nil?
    render(
      partial: 'partials/table', locals: {
        table_name: table_name, aoData: aoData, columns: columns, sort: sort,
        table_filters: table_filters, table_views: table_views,
        initial_size: initial_size, table_actions: table_actions,
        table_url: table_url
      }.merge(request.query_parameters), formats: [:html]
    )
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
zuora_connect_ui-0.12.3 app/helpers/datatable_helper.rb
zuora_connect_ui-0.12.2 app/helpers/datatable_helper.rb
zuora_connect_ui-0.12.1 app/helpers/datatable_helper.rb
zuora_connect_ui-0.12.0 app/helpers/datatable_helper.rb
zuora_connect_ui-0.11.10 app/helpers/datatable_helper.rb
zuora_connect_ui-0.11.9 app/helpers/datatable_helper.rb
zuora_connect_ui-0.11.8 app/helpers/datatable_helper.rb
zuora_connect_ui-0.11.7 app/helpers/datatable_helper.rb
zuora_connect_ui-0.11.6 app/helpers/datatable_helper.rb
zuora_connect_ui-0.11.5 app/helpers/datatable_helper.rb
zuora_connect_ui-0.11.4 app/helpers/datatable_helper.rb
zuora_connect_ui-0.11.3 app/helpers/datatable_helper.rb
zuora_connect_ui-0.11.2 app/helpers/datatable_helper.rb
zuora_connect_ui-0.11.1 app/helpers/datatable_helper.rb
zuora_connect_ui-0.11.0 app/helpers/datatable_helper.rb
zuora_connect_ui-0.10.3 app/helpers/datatable_helper.rb
zuora_connect_ui-0.10.2 app/helpers/datatable_helper.rb
zuora_connect_ui-0.10.1 app/helpers/datatable_helper.rb
zuora_connect_ui-0.10.0 app/helpers/datatable_helper.rb
zuora_connect_ui-0.9.2 app/helpers/datatable_helper.rb