Topic: form with tablegrid that takes time to load

I've been using a form with a tablegrid to access 32,000 records. The tablegrid is loaded through a button with the search function, native to MVD, and the grid line colors are alternated with the script below, which I got from this forum. I know that if the grid has many columns, it will take a longer time to load the data. Does anyone know if there's a solution for this? MVD is fantastic, but I've run into this problem in a few applications I've built. Would it be the case of having a script that loaded only part of the tablegrid and loaded the rest of the records as the user clicked on pageup or pagedown?

procedure alterna_cor_linha_os;
//*** Proc 741 - alterna cor nas linhas de um grid - procedure serve para qualquer grid
begin
  ColorRowGrid(frm_lista_os.TableGrid_OS,clWindow,$00C6E2FF, false);
end;

procedure ColorRowGrid (Grid:TdbStringGridEx;ColorEven,ColorOdd:TColor;ajusta:boolean);
//*** Proc 741 - alterna cor nas linhas de um grid - procedure serve para qualquer grid
var
   iRow ,c: integer;
   q, iCol: integer;
begin
     Grid.BeginUpdate;
     c := Grid.RowCount - 1;
     q := Grid.Columns.Count-1;
     for iRow := 0 to c do
         for iCol := 0 to q do
         begin
             if iRow mod 2 = 0 then Grid.Cell[iCol,iRow].Color := ColorEven
             else
             Grid.Cell[iCol,iRow].Color := ColorOdd;
         end;
         if ajusta then Grid.BestFitColumns(bfBoth); //ajusta conteúdo no tablegrid
     Grid.EndUpdate;
end;
Roberto Alencar

2 (edited by k245 2023-08-29 05:56:16)

Re: form with tablegrid that takes time to load

You are on the right track: for so many posts, you need to use pagination. The question of whether it is necessary to load records as the grid scrolls is debatable for me. It is easier to use special buttons for page loading, as is usually done on sites.

Визуальное программирование: блог и телеграм-канал.

Re: form with tablegrid that takes time to load

Hello jrga, Hello K245

A possible explanation: Does your database include images?
If so, how do you integrate them: Directly in the database (via StoreFile) or in a dedicated folder (via LinkFile and CopyTo\MyFolder)?

In the first case, the more images you store directly, the more your database will take on weight and therefore take time to load.
In the second case, your database will only be enriched by the path to store your images in their chosen folder.

Alternatively, you could use the couple BeginUpdate and EndUpdate.
J.B.

For K245

Are you still interested in my French translation of your files?

JB

Re: form with tablegrid that takes time to load

jean.brezhonek wrote:

For K245

Are you still interested in my French translation of your files?

JB

Yes, I will gladly publish them ))

Визуальное программирование: блог и телеграм-канал.

Re: form with tablegrid that takes time to load

Hi all.

Of course you output 32000 entries. Let's multiply them by the number of columns.
Now you start iterating over EVERY CELL. Then you align the columns.
Perhaps you have missed sorting in the program and this also takes time.


And you are just coloring the lines through one.


In my opinion, you should ask yourself the question: do I really need to display 32000 entries on the screen?
Are you really viewing all 32000 records? What if there are more of them over time?
Why are you going the Excel route? Display everything on the screen and then we will understand.
From your words you worked with databases. You can initially find and display what you need.
An exception may be the process of output to a report. But even this is not rational in our time.
After all, all records are available at any time.

Re: form with tablegrid that takes time to load

A test application that implements the principle of page-by-page display of data. You can experiment with the page size and number of entries to see the performance.

Post's attachments

Attachment icon Много записей.rar 302.02 kb, 93 downloads since 2023-08-30 

Визуальное программирование: блог и телеграм-канал.

7 (edited by k245 2023-08-30 05:39:10)

Re: form with tablegrid that takes time to load

http://myvisualdatabase.com/forum/misc.php?action=pun_attachment&item=9822&download=0

Post's attachments

Attachment icon изображение_2023-08-30_083833310.png 13.25 kb, 21 downloads since 2023-08-30 

Визуальное программирование: блог и телеграм-канал.

8 (edited by jrga 2023-08-31 13:37:46)

Re: form with tablegrid that takes time to load

K245, obrigado pelo exemplo que enviou.

Acabei criando minha própria solução, mas pretendo analisar melhor a sua proposta. Abraços.

procedure frm_lista_os_btn_busca_OnClick (Sender: TObject; var Cancel: boolean);
var
   dados_filtro : string;
begin
   dados_filtro := '';

   dados_filtro :=
   frm_lista_os.Edit_ID.text +
   frm_lista_os.cbo_cliente.text +
   frm_lista_os.cbo_aparelho.text +
   frm_lista_os.cbo_marca.text +
   iif2(frm_lista_os.chk_impresso.sqlValue = 'NULL','','*') +
   iif2(frm_lista_os.DateTimePicker_aprovacao.sqlDate = 'NULL','','*') +
   iif2(frm_lista_os.DateTimePicker_entrada.sqlDate = 'NULL','','*') +
   iif2(frm_lista_os.DateTimePicker_entrega.sqlDate = 'NULL','','*') +
   frm_lista_os.Edit_modelo.text +
   frm_lista_os.Edit_obs.text +
   frm_lista_os.Edit_pagto.text +
   frm_lista_os.Edit_pecas.text +
   frm_lista_os.Edit_serie.text;

   //showmessage(dados_filtro);
   //frm_lista_os.TableGrid_OS.dbLimit := 500;

   if length(dados_filtro) then
       frm_lista_os.TableGrid_OS.dbLimit := 0
   else
   begin
         if messagedlg('Exibe: (Yes) todos ou (No) somente 500 ?',mtwarning,mbyes+mbno,0) = mryes then
            frm_lista_os.TableGrid_OS.dbLimit := 0
         else
            frm_lista_os.TableGrid_OS.dbLimit := 500;
   end;
end;

Function IIF2( bln:boolean; TruePart:string; FalsePart:string):string;
begin
  if bln then
    Result := TruePart
  else
    Result := FalsePart;
end;
Roberto Alencar

Re: form with tablegrid that takes time to load

Hello,
I am facing similar problem. The patient register form takes about 9-10 seconds to load. Is it possible to set a filter in the table grid settings to display last 20 entries or entries made in last 1 week only?
Regards,
Eyeman

Post's attachments

Attachment icon Screenshot 2024-01-21 115855 tablegrid.png 88.61 kb, 11 downloads since 2024-01-21 

Re: form with tablegrid that takes time to load

Hi Eyeman,
Hope you're keeping well.
Yes you could always limit the initial load to a set number of records with a filter than runs when you start your program.
However, from the screenshot, I see that you're only loading 2482 records (can't see that any filters have been applied);   if I remember rightly, that will be from the lead table 'opd_registration' which isn't really that many rows (notwithstanding your large number of tables and relationships).
So I'm wondering if there are other things that are making your program run slowly.
Maybe it would be better if you upload your project and people could have a look and see if there are other areas that could be looked at to improve performance (for example, the number of calculated fields or if you're looping through grids to apply column formatting etc etc).
If you have concerns about data privacy, you could always take a copy of your project and then anonymise the names before zipping and uploading.
By the way, love the 'LifeStatus' of 'Alive&Kicking' big_smile
Regards,
Derek.

11 (edited by eyeman303 2024-01-22 17:34:47)

Re: form with tablegrid that takes time to load

Hello Derek,
How do you do? I am ok. Thanks for your reply. Only this form tends to open slowly, possibly due to many relationships and calculated fields as you correctly remember.
I have now added a filter id>2000 and a second table grid for search results. That way the form loads fast, can see/edit the recent registrations and search the database for old patients. The application is helping run my clinic efficiently. I send out birthday greetings by WhatsApp everyday to patients. Occasionally was embarrassed by relatives of deceased patients. So added a column Life_Status!
I am indebted to you and other experts in this Forum who have helped me  from the very beginning and at every step of its development. I will upload the project some time later for scrutiny. Surely there will be many areas to improve.
Regards,
Eyeman

Post's attachments

Attachment icon Screenshots.zip 1.48 mb, 40 downloads since 2024-01-22