> -----Original Message-----
> From: wxperl-users-admin@xxxxxxxxxxxxxxxxxxxxx
> [mailto:wxperl-users-admin@xxxxxxxxxxxxxxxxxxxxx]On Behalf Of Mattia
> Barbon
> Sent: December 6, 2003 1:06 PM
> To: Thomas Klausner; wxperl-users@xxxxxxxxxxxxxxxxxxxxx
> Subject: Re: [wxperl-users] Grids and Data
>
>
> Il Tue, 2 Dec 2003 10:23:17 +0100 Thomas Klausner <domm@xxxxxx>
> ha scritto:
>
> Hello,
>
> > I'm currently developing a small application for in-house use.
> > Basically,
> > it's a database front end, i.e. users should be able to view,
> > insert, edit,
> > delete some data.
> >
> > I got some basic stuff working, but I'm wondering if there is a
> > "standard"
> > way of generating a Wx::Grid from database data.
> No, there isn't.
>
> > Here's what I'm doing:
> > in MyApp::new, I set up a panel, and generate a grid
> >
> > my $grid=Wx::Grid->new($panel,-1,wxDefaultPosition,[750,300]);
> >
> > I fetch stuff from a database (using Class::DBI):
> >
> > my @ks=ZCont::DB::Kostenstelle->retrieve_all;
> > my $rows=@ks || 1;
> > $grid->CreateGrid($rows,7);
> >
> > foreach my $kostenstelle (@ks) {
> > my $row=0;
> > my $col=0;
> > foreach(qw(kostenstelle titel beginn ende leitung overhead
> > budget)) {
> > $grid->SetCellValue($row,$col,$kostenstelle->$_);
> > $col++;
> > }
> > $row++;
> > }
> >
> > (If you're not familiar with Class::DBI : @ks is an array containing
> > objects. Each object as accessors which correlate to a column)
> >
> > This is working as expected, but there might be some better ways to
> > set up a
> > Grid ?
> Using a custom Wx::GridTable (there is a xample in the wxPerl demo)
> might be a good idea.
>
> > Additionally, some more questions (I'm coming from a Web
> > background..):
> >
> > Say I've got 1000 rows in a table, but only want to display 100 in
> > a Grid,
> > would I:
>
> > * fetch all 1000 columns and add/delete them from the Grid if the
> > user pages
> > up/down
> >
> > * fetch only 100, delete them when they disappear from the screen,
> > and fetch
> > new ones if they are needed (this is what I would do in a Web
> > Environment,
> > which is stateless)
> >
> > * something completly different?
> It depends. I think that, for a GUI application, it is better to display
> all 1000 rows at once and let the user scroll them using the scrollbars.
> If you use a custom Wx::GridTable you can fetch the rows on demand
> (thus avoiding fetching a large amount of data the user might not
> need/look at).
>
> HTH
> Mattia
>
> P.S.: I think that a generic "Database Grid" might be a good
> candidate for CPAN.
> if you feel like releasing it
>
I am also using Wx::Grid to display database data. Here is a snippet of code
I use to fill the grid using a statement handle. (The columns are
initialized elsewhere in the code)
my $max_col = $self->GetNumberCols() - 1;
my @row;
$sth->bind_columns( \( @row[ 0 .. $max_col ] ) );
my $row_count = 0;
my $col_count = 0;
while ( $sth->fetch() ) {
$self->AppendRows(1);
$self->SetCellValueXY( $row_count, $col_count++, $_ )
for (@row);
$row_count++;
$col_count = 0;
}
I was using Class::DBI methods to fill the grid much as Thomas was but I
found it too slow once the number of records gets higher. I am looking at
using Wx::GridTable but my performance is good enough right now (largest
grid is around 8 columns and close to a 1000 rows so not too big) so I have
not bothered.
My custom Wx::Grid class also allows the user to filter/sort any visible
column. If anyone is interested let me know and I will clean up the code,
comment it better, remove stuff specific to my application and post it.
Brad
-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills. Sign up for IBM's
Free Linux Tutorials. Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click
|