Dear Monks,

I am using TableMatrix to show data from a SQLite database. Queries may produce 2 rows of data or 1000... I'd like to change the number of rows of the table according to this value (the value should be easly get from SQLite, I think I read about a command).

Any idea on how to update (number of rows) an existing TableMatrix? I tried different approches, but nothing seems to let the TableMatrix to get updated (I hust want to avoid destroing and rebuilding the TableMatrix for every query!)

Here is my code:

sub create_table { $arrayVar = {}; ($rows,$cols) = (5000, 6); foreach my $row (0..($rows-1)){ $arrayVar->{"$row,0"} = "$row"; } foreach my $col (0..($cols-1)){ $arrayVar->{"0,$col"} = "$col"; } #Creating Table... sub colSub{ my $col = shift; return "OddCol" if( $col > 0 && $col%2) ; } $t = $frame_d->Scrolled('TableMatrix', -state=>'disabled', -rows => $rows, -cols => $cols, -width => 6, -bg=>'white', -height => 12, -titlerows => 1, -titlecols => 1, -variable => $arrayVar, -coltagcommand => \&colSub, -browsecommand => \&brscmd, -colstretchmode => 'last', -flashmode => 1, -flashtime => 2, -wrap=>1, -rowstretchmode => 'last', -selectmode => 'extended', -selecttype=>'row', -selecttitles => 0, -drawmode => 'fast', -scrollbars=>'se', -sparsearray=>0, )->pack(-expand => 'both', -fill => 'both'); }

Before a new query I just clean the table

#clear table sub clear_table{ foreach my $row(1..$rows){ foreach my $col(1..$cols){ $arrayVar->{"$row,$col"} = ""; } } }

The problem with my solution is that if a have a table with for example 3000 rows, but only 20 rows of data, the scrolling through the table is not very confortable.

Any suggestion is very much appreciated!

Cla


In reply to TableMatrix and dinamically set the number of rows by fanticla

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.