Closed prospectoria closed 9 years ago
This appears to be working (in the tardis branch), here is the perl script I use on the back-end (for those it may help)
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
use CGI;
use JSON;
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
my $q = new CGI();
my $sql = $q->param('sql');
if(!defined($sql)) {
print $q->header(-type => 'application/json');
print "{'status':'fail','msg':'sql not defined'}";
}
my @args = $q->url_param('arg');
my $rp = $q->param('rp'); # number per page
my $page = $q->param('page'); # current page
if(!(defined $page) || $page eq '') {
$page = 1;
}
if(!(defined $rp) || $rp eq '') {
$rp=20;
}
# calculate our start/end rows
$page -= 1;
my $r0 = $page * $rp;
my $r1 = $r0 + $rp;
# $dbconf comes from some custom config stuff from my app. Replace this with your local
database connectity code
# to get your database handle
my $DSN = "DBI:mysql:".$dbconf{'dbname'}.";mysql_read_default_file=".$dbconf{'deffile'};
my $dbh = DBI->connect($DSN, $dbconf{'user'}, $dbconf{'pass'},
{'RaiseError' => 0, 'PrintError' => 0});
$sql =~ s/\"/\`/g; # mysql/perl DBI will not work with quotes (at least in my current setup)
my $sth = $dbh->prepare($sql);
$sth->execute(@args);
my @rowsout;
my $retstr = {};
my $count = -1;
while(my @row = $sth->fetchrow_array()) {
$count++;
# TODO: replace this with $sth->rows
if ($count < $r0 || $count >= $r1) {
next;
}
# TODO: Add types for fields, i.e. string/int, etc.
# loop through each column
push(@rowsout, { 'cell' => \@row });
}
$retstr->{page} = $page +1;
$retstr->{total} = $count +1;
$retstr->{rows} = \@rowsout;
my $j = JSON->new;
print $q->header(-type => 'text/json');
print $j->utf8->encode($retstr);
I'm closing this one as it is working as spec'd tyvm. Please re-open if there are still issues.
Add Lazy Scrolling to gwt-Suggestbox. Currently when you type a character into the gwt-Suggestbox it displays a list of 20 values. We need to be able to scroll this list and when we scroll to the end it should send a request for the next 20 values. This means that the ajax call that populates this list will also have to send a page number that is incremented every time a scroll down to the end occurs.