Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: Sortable table using Gtk2 in UI application

by SyneRohit (Initiate)
on Oct 03, 2011 at 10:10 UTC ( #929304=note: print w/ replies, xml ) Need Help??


in reply to Re: Sortable table using Gtk2 in UI application
in thread Sortable table using Gtk2 in UI application

Thank you. This solution worked for me.


Comment on Re^2: Sortable table using Gtk2 in UI application
Re^3: Sortable table using Gtk2 in UI application
by zentara (Archbishop) on Oct 03, 2011 at 12:15 UTC
    Your welcome. After posting that example code, I extended it to multicolumn sorting. You may find this example even better. It sorts on each column, by clicking that column header.
    #!/usr/bin/perl use warnings; use strict; use Gtk2 -init; use Gtk2::SimpleList; my $win = Gtk2::Window->new; $win->signal_connect (delete_event => sub { Gtk2->main_quit; }); my $vbox = Gtk2::VBox->new; $win->add ($vbox); my $slist = Gtk2::SimpleList->new ( 'Int' => 'int', 'Text' => 'text' ) +; @{$slist->{data}} = ( [11, 'text1'], [21, 'text2'], [3, 'text3'], [41, + '4text'] ); $slist -> set_reorderable( 1 ); #my @columns = $slist->get_columns; #for (my $i = 0 ; $i < @columns ; $i++) { #$columns[$i]->set_sort_column_id ($i); #} # or $slist->get_column (0)->set_sort_column_id (0); $slist->get_column (1)->set_sort_column_id (1); $slist->get_column(0)->signal_connect( clicked => sub { warn "clicked 0!\n" } ); $slist->get_column(1)->signal_connect( clicked => sub { warn "clicked 1!\n" } ); $vbox->add ($slist); my $button = Gtk2::Button->new('Show Data'); $vbox->pack_end( $button, 0, 0, 0 ); $button->signal_connect( clicked => sub { print @{$slist->{data}},"\n"; # demonstrates reordering foreach my $arr ( @{$slist->{data}} ){ print "$arr->[0]\t$arr->[1]\n" } print "\n\n"; } ); $win->show_all; Gtk2->main;

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://929304]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (15)
As of 2015-07-06 17:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (77 votes), past polls