@@ -136,6 +136,10 @@ def sort_data
136136 # @param row_dom_id [Boolean]
137137 # Whether each `<tr>` additionally gets a DOM `id`, namespaced by the
138138 # table id to stay unique across tables. Requires `row_id`.
139+ # @param row_classes [Proc, nil]
140+ # Optional `->(row)` returning extra CSS classes for the row's `<tr>`.
141+ # @param row_data [Proc, nil]
142+ # Optional `->(row)` returning a Hash of data attributes for the row's `<tr>`.
139143 # @param html_data [Hash]
140144 # HTML data attributes to be passed to the table
141145 # @param system_arguments [Hash]
@@ -150,6 +154,8 @@ def initialize(
150154 divider : false ,
151155 row_id : nil ,
152156 row_dom_id : false ,
157+ row_classes : nil ,
158+ row_data : nil ,
153159 html_data : { } ,
154160 **system_arguments
155161 )
@@ -161,6 +167,8 @@ def initialize(
161167 @sort_href_builder = sort_href_builder
162168 @divider = fetch_or_fallback_boolean ( divider , false )
163169 @row_id_proc = row_id
170+ @row_classes_proc = row_classes
171+ @row_data_proc = row_data
164172 @row_dom_id = fetch_or_fallback_boolean ( row_dom_id , false )
165173 raise ArgumentError , "`row_dom_id` requires a `row_id` proc" if @row_dom_id && @row_id_proc . nil?
166174 @id = system_arguments [ :id ] ||= self . class . generate_id ( base_name : "data-table" )
@@ -349,14 +357,19 @@ def grid_template_from_columns(columns)
349357 end
350358
351359 def row_arguments ( row )
352- arguments = { classes : "TableRow" }
353- return arguments unless @row_id_proc
360+ arguments = { classes : class_names ( "TableRow" , @row_classes_proc &.call ( row ) ) }
354361
355- value = @row_id_proc . call ( row ) . to_s
356- return arguments if value . blank?
362+ data = ( @row_data_proc &.call ( row ) || { } ) . to_h
357363
358- arguments [ :data ] = { row_id : value }
359- arguments [ :id ] = "#{ @id } -row-#{ value } " if @row_dom_id
364+ if @row_id_proc
365+ value = @row_id_proc . call ( row ) . to_s
366+ if value . present?
367+ data = data . merge ( row_id : value )
368+ arguments [ :id ] = "#{ @id } -row-#{ value } " if @row_dom_id
369+ end
370+ end
371+
372+ arguments [ :data ] = data if data . any?
360373 arguments
361374 end
362375
0 commit comments