22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/table_helpers.rb', line 22
def (columns=[], widths={})
= []
p = params
i = 1
for j in 0 .. columns.length - 1
column_name = columns[j][0]
sort_columns = columns[j][1..columns[j].length-1]
if sort_columns.present?
if params[:order_by] == sort_columns.join(', ')
link = link_to(column_name, p.merge('order_by' => "#{sort_columns.join(' DESC, ') + ' DESC'}"), :class=> "sortdown")
elsif params[:order_by] == sort_columns.join(' DESC, ') + ' DESC'
link = link_to(column_name, p.merge('order_by' => sort_columns.join(', ')), :class=> "sortup")
else
link = link_to(column_name, p.merge('order_by' => sort_columns.join(', ')), :class=> "sort-none")
end
if widths.has_key?(i)
.push("<th width=\"%s\">%s</th>" % [widths[i],link])
else
.push("<th>%s</th>" % [link])
end
elsif column_name.present?
.push('<th>%s</th>' % column_name)
else
.push('<th></th>')
end
i += 1
j += 1
end
.join.html_safe
end
|