# Table with selectable rows

**URL:** <https://www.ruby-forum.com/t/table-with-selectable-rows/149134>\
**Category:** Rails\
**Created:** [September 21, 2008, 10:23am UTC](https://www.ruby-forum.com/t/table-with-selectable-rows/149134 "2008-09-21T10:23:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AdamT](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/96bed5/32.png) [@AdamT](https://www.ruby-forum.com/u/AdamT)\
**Post date:** [September 21, 2008, 10:23am UTC](https://www.ruby-forum.com/t/table-with-selectable-rows/149134/1 "2008-09-21T10:23:59Z")

</div>

I need a table with selectable rows (there is a check box in every  
row). All selected rows should be displayed with different style than  
rows which are not selected.  
I implemented this behavior by assigning the css-defined class to

  
tag class="unchecked\_msg"\>

and toggling the class whenever checkbox is clicked.

\<%= check\_box\_tag(“checked\_messages[]”, object.id,  
false, :class=\>“selectable\_msg”, :align=\>“top”, :onchange =\> “$  
(‘msgrow\_#{object.id}’).toggleClassName(‘checked\_msg’,  
‘unchecked\_msg’);”) %\>

It works fine until user refreshes page. After the refresh checkbox is  
still checked, but the class of the row is reset to “unchecked\_msg”.  
Anyone has an idea how to survive page refresh?

thanks,  
Adam

---

<div class="post-metadata">

**Author:** ![AdamT](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/96bed5/32.png) [@AdamT](https://www.ruby-forum.com/u/AdamT)\
**Post date:** [September 21, 2008, 4:33pm UTC](https://www.ruby-forum.com/t/table-with-selectable-rows/149134/2 "2008-09-21T16:33:06Z")

</div>

only way: make an ajax call, whenever the checkbox is clicked.  
in the backend store the new value in the session or database  
and use this information to rebuild the whole page for a refresh

---

<div class="post-metadata">

**Author:** ![AdamT](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/96bed5/32.png) [@AdamT](https://www.ruby-forum.com/u/AdamT)\
**Post date:** [September 21, 2008, 4:37pm UTC](https://www.ruby-forum.com/t/table-with-selectable-rows/149134/3 "2008-09-21T16:37:12Z")

</div>

On Sun, Sep 21, 2008 at 10:23 AM, AdamT [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> \<%= check\_box\_tag(“checked\_messages[]”, object.id,  
> false, :class=\>“selectable\_msg”, :align=\>“top”, :onchange =\> “$  
> (‘msgrow\_#{object.id}’).toggleClassName(‘checked\_msg’,  
> ‘unchecked\_msg’);”) %\>
> 
> It works fine until user refreshes page. After the refresh checkbox is  
> still checked, but the class of the row is reset to “unchecked\_msg”.  
> Anyone has an idea how to survive page refresh?

Instead of hard-coding the classes write a dom:loaded observer in  
JavaScript that iterates over the rows and assigns the class as  
needed.
