# Sort & scrollable table

**URL:** <https://www.ruby-forum.com/t/sort-scrollable-table/117221>\
**Category:** Rails\
**Created:** [October 14, 2007, 11:39pm UTC](https://www.ruby-forum.com/t/sort-scrollable-table/117221 "2007-10-14T23:39:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hallikpapa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/90db22/32.png) [@hallikpapa](https://www.ruby-forum.com/u/hallikpapa)\
**Post date:** [October 14, 2007, 11:39pm UTC](https://www.ruby-forum.com/t/sort-scrollable-table/117221/1 "2007-10-14T23:39:32Z")

</div>

So I have a show.rhtml that displays XML data generated from perl. The  
column headers are the element tags in the XML, enclosing the data. I  
have two questions

1. How would I make the columns sortable when a user clicks on the  
column header; ASC/DESC?

2. How would you create a text box that would allow me to filter the  
results? For instance, if a column was labeled “State”, I could switch  
the filter to state, and Just type a “T”, and only rows with a state  
starting with a T would be displayed.

Is there a plugin or an easy way to do these two things?

---

<div class="post-metadata">

**Author:** ![hallikpapa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/90db22/32.png) [@hallikpapa](https://www.ruby-forum.com/u/hallikpapa)\
**Post date:** [October 14, 2007, 11:40pm UTC](https://www.ruby-forum.com/t/sort-scrollable-table/117221/2 "2007-10-14T23:40:22Z")

</div>

Here is my table ion the show.rhtml

```
<thead>
  <tr>

```

\<%  
link\_index = nil  
@report.columns.each do |col|  
if(col.name.downcase == ‘link’ || col.name.downcase == ‘label’)  
link\_index = col.name

-%\>

  
\<%  
else  
-%\>  

\<%  
end  
end  
-%\>

  
\<%= ‘

Sorry, no results were found with the  
supplied parameters

’ if @report.rows.size == 0 %\>  
\<%  
@report.rows.each do |row|  
if link\_index  
-%\>  
\<tr class=“clickable \<%= cycle(”", “shade”) -%\>"  
onclick=“window.location=’\<%= url\_for :action =\> ‘drill\_down’, :params  
=\> { :url =\> CGI.escape(row[link\_index])} %\>’”\>  
\<%  
else  
-%\>  
\<tr class="\<%= cycle("", “shade”) -%\>"\>  
\<%  
end  
@report.columns.each do |col|  
if (col.name != link\_index)  
-%\>  
  
\<%  
else  
-%\>  
  
\<%  
end  
end  
-%\>  
  
\<%  
end  
-%\>  

| Drill Down Avail | \<%= col.human\_name %\> |
| --- | --- |
| \<%= row[col.name] %\> | \<%= link\_to ‘+’, :action =\> ‘drill\_down’, :params =\> { :url  
=\> CGI.escape(row[link\_index])} %\> |

---

<div class="post-metadata">

**Author:** ![hallikpapa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/90db22/32.png) [@hallikpapa](https://www.ruby-forum.com/u/hallikpapa)\
**Post date:** [October 15, 2007, 2:57am UTC](https://www.ruby-forum.com/t/sort-scrollable-table/117221/3 "2007-10-15T02:57:27Z")

</div>

will\_paginate MAY do what I need, but I am not reading from a table. I  
do a call to a perl script which returns an XML stream/response that  
ruby catches.

the examples I am seeing is reading from a table. How would I do set  
this up when the data is coming from an XML stream and not a database?
