Jump to content
toufik

Tlistview SQLite pagination

Recommended Posts

hello every one ...
I'm trying pagination with SQLite database using live binding with a  tlistview  i did try using this guide:

DB Pagination and TListView question - Databases - Delphi-PRAXiS [en] (delphipraxis.net)
with some modification so i added the implement of pagination on  PullToRefresh of the tlistview and work's fine .

the problem that .... i want to keep the items that added to the tlistview every PullToRefresh and so on 
the code I used, can anyone point me to the right direction. 
 

procedure TFormMain.ListView2MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Single);
begin
 if PullToRefreshCheck then
 begin
   if (Y-RefreshPos)>40 then    begin
  if (FDTableTask.RecordCount < lMyMaxRecordsByPage) then
    exit;
  //
  FDTableTask.Disconnect;
  FDTableTask.FetchOptions.RecsSkip := FDTableTask.FetchOptions.RecsSkip + lMyMaxRecordsByPage;
  FDTableTask.Open();

    Label48.Text := '...تحديث';
     Label48.Visible := True;
     Timer3.Enabled := True;
     PullToRefreshCheck := False;
     RefreshPos := 0;
   end else begin
Label48.Text := 'u retched the end ';
end;
 end;

 

 

Edited by toufik

Share this post


Link to post
3 hours ago, toufik said:

i want to keep the items that added to the tlistview every PullToRefresh and so on 

@toufik

then, you would can try some like this: no pagination, in fact, but just increase the param used in "LIMIT" in your select

 

  • ex.: 1 ... 20 = 20 records on LV
    • 1... 40 = 20 + 20 records on LV
    • 1... 60 = 20 + 20 + 20 .... etc...
  • YourQUERY.Text := SELECT ... from TableXXX LIMIT "n"   --> n= 20, n=40, n=60, etc...
    • you can try use "params" in your select to change the value in "n"
    • Quote

      object FDQuery1: TFDQuery
          Connection = FDConnection1
          SQL.Strings = (
            'select * from tablex LIMIT :n')
          Left = 416
          Top = 232
          ParamData = <
            item
              Name = 'N'
              DataType = ftInteger
              ParamType = ptInput
              Value = Null
            end>

       

  • YourQUERY.Last ---> go to last record on screen or any other way to show last 20 records in your LV
    • LiveBinding use o "BindSourceDB" then you try this: "BindSourceDB1.DataSet.Last"
  • Thanks 1

Share this post


Link to post

using "Dataset" (FireDac or any other) you can try this: after your "SELECT" 

  • here my sample using a EMPLOYEE Interbase db:  "SELECT * FROM CUSTOMER ROWS :N "  --> N = param "Integer"
implementation

{$R *.dfm}

//type
//  TMyHack = class(TDBGrid);

var
  LDBGridVisibleRows: integer;
  LNextRecord       : integer;

procedure TForm1.FormCreate(Sender: TObject);
begin
  LDBGridVisibleRows := 10; // TMyHack(DBGrid1).RowCount; // or your LV visible items on screen!!!
  LNextRecord        := LDBGridVisibleRows;
  //
  CustomerTable.Open;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  CustomerTable.ParamByName('N').AsInteger := LNextRecord;
  CustomerTable.Refresh;
  CustomerTable.Last;
  //
  LNextRecord := LNextRecord + LDBGridVisibleRows;
  //
  CustomerTable.MoveBy(-LDBGridVisibleRows)
end;

 

Project1_l0iTglarsE.gif

Edited by programmerdelphi2k
  • Thanks 1

Share this post


Link to post

to avoid more clicks...

procedure TForm1.Button1Click(Sender: TObject);
begin
  CustomerTable.ParamByName('N').AsInteger := LNextRecord;
  CustomerTable.Refresh;
  CustomerTable.Last;
  //
  if (LNextRecord >= CustomerTable.RecordCount) then // not more records...
    Button1.Enabled := false;
  //
  LNextRecord := LNextRecord + LDBGridVisibleRows;
  //
  CustomerTable.MoveBy(-LDBGridVisibleRows)
end;

 

Edited by programmerdelphi2k
  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×