Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re^3: Sortable table using Gtk2 in UI application

by zentara (Archbishop)
on Oct 03, 2011 at 12:15 UTC ( #929314=note: print w/ replies, xml ) Need Help??

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

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?

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2016-07-24 04:57 GMT
Find Nodes?
    Voting Booth?
    What is your favorite alternate name for a (specific) keyboard key?

    Results (221 votes). Check out past polls.