app/components/katalyst/table_component.rb in katalyst-tables-2.6.0 vs app/components/katalyst/table_component.rb in katalyst-tables-3.0.0.beta1

- old
+ new

@@ -27,18 +27,20 @@ # of options for customizing the table. The most common options are: # - `collection`: the collection to render # - `sorting`: the sorting to apply to the collection (defaults to collection.storing if available) # - `header`: whether to render the header row (defaults to true, supports options) # - `caption`: whether to render the caption (defaults to true, supports options) + # - `generate_ids`: whether to generate ids for each row (defaults to true) # - `object_name`: the name of the object to use for partial rendering (defaults to collection.model_name.i18n_key) # - `partial`: the name of the partial to use for rendering each row (defaults to to_partial_path on the object) # - `as`: the name of the local variable to use for rendering each row (defaults to collection.model_name.param_key) # In addition to these options, standard HTML attributes can be passed which will be added to the table tag. def initialize(collection:, sorting: nil, header: true, - caption: false, + caption: true, + generate_ids: true, **html_attributes) @collection = collection # sorting: instance of Katalyst::Tables::Collection::SortForm. # If not provided will be inferred from the collection. @@ -50,13 +52,19 @@ # caption: true means render the caption, caption: false means no caption, if a hash, passes as options @caption = caption @caption_options = (caption if caption.is_a?(Hash)) || {} + @generate_ids = generate_ids + super(**html_attributes) end + def id + html_attributes[:id] + end + def caption? @caption.present? end def caption @@ -77,9 +85,13 @@ def sorting return @sorting if @sorting.present? collection.sorting if collection.respond_to?(:sorting) + end + + def generate_ids? + @generate_ids.present? end def inspect "#<#{self.class.name} collection: #{collection.inspect}>" end