# Sorting Grid by column

**URL:** <https://www.ruby-forum.com/t/sorting-grid-by-column/151920>\
**Category:** wxRuby\
**Created:** [October 27, 2008, 10:20pm UTC](https://www.ruby-forum.com/t/sorting-grid-by-column/151920 "2008-10-27T22:20:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Glen\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/34f0e0/32.png) [@Glen\_H](https://www.ruby-forum.com/u/Glen_H)\
**Post date:** [October 27, 2008, 10:20pm UTC](https://www.ruby-forum.com/t/sorting-grid-by-column/151920/1 "2008-10-27T22:20:24Z")

</div>

What would be the best way to sort a grid by the column the user clicks  
on?  
I have a bunch of database info being represented in grids (via  
GridTableBase) that I would like to be sortable by different columns. I  
didn’t see anything in the Grid or GridTableBase about a column select  
event.

Thanks,  
Glen

–  
“Hey brother Christian with your high and mighty errand, Your actions  
speak  
so loud, I can’t hear a word you’re saying.”

-Greg Graffin (Bad Religion)

---

<div class="post-metadata">

**Author:** ![Glen\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/34f0e0/32.png) [@Glen\_H](https://www.ruby-forum.com/u/Glen_H)\
**Post date:** [October 30, 2008, 4:33am UTC](https://www.ruby-forum.com/t/sorting-grid-by-column/151920/2 "2008-10-30T04:33:17Z")

</div>

Glen H. wrote:

> What would be the best way to sort a grid by the column the user  
> clicks on? I have a bunch of database info being represented in grids  
> (via GridTableBase) that I would like to be sortable by different  
> columns. I didn’t see anything in the Grid or GridTableBase about a  
> column select event.  
> There is an event evt\_grid\_label\_left\_click which is fired when a row or  
> column header is clicked on. You can call get\_col on the event object to  
> find out which column was clicked. There are also similar events for  
> right clicks and double clicks.

To re-order a column, I think it should be enough to change what  
GridTableBase is returning in your case, and then calling refresh on the  
Grid.

To select a whole column just use Grid#select\_col method.

cheers  
alex

---

<div class="post-metadata">

**Author:** ![Glen\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/34f0e0/32.png) [@Glen\_H](https://www.ruby-forum.com/u/Glen_H)\
**Post date:** [November 3, 2008, 8:46pm UTC](https://www.ruby-forum.com/t/sorting-grid-by-column/151920/3 "2008-11-03T20:46:06Z")

</div>

On Mon, Oct 27, 2008 at 5:10 PM, Alex F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> find out which column was clicked. There are also similar events for right
> 
> * * *
> 
> wxruby-users mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [http://rubyforge.org/mailman/listinfo/wxruby-users](http://rubyforge.org/mailman/listinfo/wxruby-users)

Thanks Alex!

It works beautifully.

-Glen

–  
“Hey brother Christian with your high and mighty errand, Your actions  
speak  
so loud, I can’t hear a word you’re saying.”

-Greg Graffin (Bad Religion)
