1 (edited by thezimguy 2018-09-01 14:06:09)

Topic: [SOLVED] TagbleGrid, Pagination, Footer and Offset

http://myvisualdatabase.com/forum/viewtopic.php?id=4447

NB: MVD 4.6 beta version is required for this to work.
Check it out

procedure Form1_OnShow (Sender: TObject; Action: string);
begin
    Form1.cbPages.ItemIndex:=4;////this will show the first 100 records
    Form1.GridEmployees.dbLimit := StrToInt((Form1.cbPages.Text));
    Form1.bSearch.Click;
end;

procedure Form1_bSearch_OnClick (Sender: TObject; var Cancel: boolean);
begin
    Form1.GridEmployees.dbLimit := StrToInt((Form1.cbPages.Text));
    Form1.GridEmployees.dbOffSet := 0;
end;             

procedure Form1_bNext_OnClick (Sender: TObject; var Cancel: boolean);
begin                                   
    Form1.GridEmployees.dbOffSet := Form1.GridEmployees.dbOffSet + StrToInt((Form1.cbPages.Text));
    Form1.GridEmployees.dbLimit := StrToInt((Form1.cbPages.Text));
    Form1.GridEmployees.dbUpdate;
end;

procedure Form1_bPrev_OnClick (Sender: TObject; var Cancel: boolean);
begin
    Form1.GridEmployees.dbOffSet := Form1.GridEmployees.dbOffSet - StrToInt((Form1.cbPages.Text));
    Form1.GridEmployees.dbLimit := StrToInt((Form1.cbPages.Text));
    if Form1.GridEmployees.dbOffSet < 0 then Form1.GridEmployees.dbOffSet := 0;
    Form1.GridEmployees.dbUpdate;
end;

procedure Form1_cbPages_OnChange(Sender: TObject; var Cancel: boolean);
begin
    if (Form1.cbPages.ItemIndex =0) then
    begin
        Form1.cbPages.ItemIndex := 1;
    end;
end;
begin
    //Form1.GridEmployees.dbLimit := 500;
end.

Download example here
http://myvisualdatabase.com/forum/viewtopic.php?id=4447

Post's attachments

Attachment icon TableGrid pagination2.png 18.23 kb, 279 downloads since 2018-07-31 

@thezimguy

Re: [SOLVED] TagbleGrid, Pagination, Footer and Offset

Thank you for the example.

Dmitry.

Re: [SOLVED] TagbleGrid, Pagination, Footer and Offset

Hello,
Please how do I select multiple rows with script in the tableGrid on a button click.
Example
When I click on button1 row 1, 2 and 5 should be selected in the tableGrid.
Meaning that when I want to print, the selected rows ate the once to print.
Tnx

@thezimguy

Re: [SOLVED] TagbleGrid, Pagination, Footer and Offset

First, you should enable it for the TableGrid, Additional > Options > goMultiSelect = True
Example:

procedure Form1_Button1_OnClick (Sender: TObject; var Cancel: boolean);
begin
    Form1.TableGrid1.Selected[0] := True;
    Form1.TableGrid1.Selected[1] := True;
    Form1.TableGrid1.Selected[4] := True;
end;
Dmitry.

Re: [SOLVED] TagbleGrid, Pagination, Footer and Offset

Wow so fast
Tnx Dmitry

@thezimguy

6 (edited by thezimguy 2018-08-20 20:56:18)

Re: [SOLVED] TagbleGrid, Pagination, Footer and Offset

Please is there a better way to achieve the effect below?
Multi select tableGrid for reporting
https://s6.postimg.cc/qy3pe1b01/multi_Select_Print.png

procedure Form1_OnShow (Sender: string; Action: string);
begin
    Form1.TableGrid1.Columns.InsertcheckboxColumn(0);
    Form1.TableGrid1.Columns[0].Header.Caption  := 'checkbox' ;
    Form1.TableGrid1.Options := Form1.TableGrid1.Options + goMultiSelect ;
    Form1.TableGrid1.OnChange := @Grid1_onChange_onClick;
    Form1.TableGrid1.OnCellClick := @Grid1_onChange_onClick;
end;

procedure Grid1_onChange_onClick(Sender: TObject; ACol, ARow: Integer);
var
    i : integer ;
begin
    for i := 0 to   Form1.TableGrid1.RowCount - 1 do
        if Form1.TableGrid1.Cell[0,i].AsBoolean then
            Form1.TableGrid1.Selected[i]:=True
        else
            Form1.TableGrid1.Selected[i]:=False;
end;

begin

end.
@thezimguy

Re: [SOLVED] TagbleGrid, Pagination, Footer and Offset

Please describe what is your goal?

Dmitry.

Re: [SOLVED] TagbleGrid, Pagination, Footer and Offset

I want to multi select rows in tableGrid so that when I click on report button it generates report for the selected rows but I don't want to use shift to do the selection

@thezimguy

Re: [SOLVED] TagbleGrid, Pagination, Footer and Offset

thezimguy wrote:

Please is there a better way to achieve the effect below?
Multi select tableGrid for reporting
https://s6.postimg.cc/qy3pe1b01/multi_Select_Print.png

procedure Form1_OnShow (Sender: string; Action: string);
begin
    Form1.TableGrid1.Columns.InsertcheckboxColumn(0);
    Form1.TableGrid1.Columns[0].Header.Caption  := 'checkbox' ;
    Form1.TableGrid1.Options := Form1.TableGrid1.Options + goMultiSelect ;
    Form1.TableGrid1.OnChange := @Grid1_onChange_onClick;
    Form1.TableGrid1.OnCellClick := @Grid1_onChange_onClick;
end;

procedure Grid1_onChange_onClick(Sender: TObject; ACol, ARow: Integer);
var
    i : integer ;
begin
    for i := 0 to   Form1.TableGrid1.RowCount - 1 do
        if Form1.TableGrid1.Cell[0,i].AsBoolean then
            Form1.TableGrid1.Selected[i]:=True
        else
            Form1.TableGrid1.Selected[i]:=False;
end;

begin

end.

I really want this.
Any help?

Re: [SOLVED] TagbleGrid, Pagination, Footer and Offset

Updated

procedure Form1_OnShow (Sender: string; Action: string);
begin
    Form1.TableGrid1.Columns.InsertcheckboxColumn(0);
    Form1.TableGrid1.Columns[0].Header.Caption  := 'checkbox' ;
    Form1.TableGrid1.Options := Form1.TableGrid1.Options + goMultiSelect ;
end;

procedure btnReport_onClick(Sender: TObject; ACol, ARow: Integer);
var
    i : integer ;
begin
    for i := 0 to   Form1.TableGrid1.RowCount - 1 do
        if Form1.TableGrid1.Cell[0,i].AsBoolean then
            Form1.TableGrid1.Selected[i]:=True
        else
            Form1.TableGrid1.Selected[i]:=False;
end;

begin

I have update the code.
This time I placed the btnReport_onClick procedure in the button click b4 the report is generated.
Im still looking forward to a better alternative

Re: [SOLVED] TagbleGrid, Pagination, Footer and Offset

procedure Form1_bReport_OnClick (Sender: TObject; var Cancel: boolean);
var
    i: integer;
begin
    for i := 0 to Form1.GridSearch.RowCount - 1 do
        Form1.GridSearch.Selected[i] := Form1.GridSearch.Cell[0,i].AsBoolean;
end;

procedure Form1_GridSearch_OnChange (Sender: TObject);
begin
    Form1.GridSearch.Columns.InsertcheckboxColumn(0);
    Form1.GridSearch.Columns[0].Header.Caption  := 'checkbox' ;
end;

Also you should enable MultiSelect option for the TableGrid: Additional > Options > goMultiSelect = True

Dmitry.

12 (edited by ekuaeshun13 2018-08-21 10:21:09)

Re: [SOLVED] TagbleGrid, Pagination, Footer and Offset

DriveSoft wrote:
procedure Form1_bReport_OnClick (Sender: TObject; var Cancel: boolean);
var
    i: integer;
begin
    for i := 0 to Form1.GridSearch.RowCount - 1 do
        Form1.GridSearch.Selected[i] := Form1.GridSearch.Cell[0,i].AsBoolean;
end;

procedure Form1_GridSearch_OnChange (Sender: TObject);
begin
    Form1.GridSearch.Columns.InsertcheckboxColumn(0);
    Form1.GridSearch.Columns[0].Header.Caption  := 'checkbox' ;
end;

Also you should enable MultiSelect option for the TableGrid: Additional > Options > goMultiSelect = True

Wow
Thank you so much
I will try it now


This is great. It works perfectly and it has corrected the error I was getting on tableGrid updates
Thank you Dmitry

Re: [SOLVED] TagbleGrid, Pagination, Footer and Offset

Hello
Please is it possible to add action icons to the tableGrid?
This icons will be for adding new record, editing and deleting records
https://s6.postimg.cc/o840rc7c1/t_Grid_with_action_icons.png

An example would be appreciated.

@thezimguy

Re: [SOLVED] TagbleGrid, Pagination, Footer and Offset

Here is an example

Post's attachments

Attachment icon Tablegrid Icons.zip 583.62 kb, 526 downloads since 2018-08-23 

Re: [SOLVED] TagbleGrid, Pagination, Footer and Offset

Thank you so much.
I will try it and communicate back to you

@thezimguy

16 (edited by derek 2018-08-23 18:20:00)

Re: [SOLVED] TagbleGrid, Pagination, Footer and Offset

Hi Thezimguy,
Is this the sort of thing you're wanting?
Please see attached.
Derek.

Sorry EH - just seen you've already replied to this and it looks like we're doing it in much the same way.  D

Post's attachments

Attachment icon actiononrow.zip 359.47 kb, 548 downloads since 2018-08-23 

Re: [SOLVED] TagbleGrid, Pagination, Footer and Offset

derek wrote:

Hi Thezimguy,
Is this the sort of thing you're wanting?
Please see attached.
Derek.

Sorry EH - just seen you've already replied to this and it looks like we're doing it in much the same way.  D

Thank you very much Derek.
I really appreciate your help

@thezimguy

18 (edited by thezimguy 2018-08-31 14:49:09)

Re: [SOLVED] TagbleGrid, Pagination, Footer and Offset

Hello Dmitry, Derek and MVD users
Please how do I reference the TableGrid using 'Sender'

Example (I can reference the caption of every Button with the code below)

bCap:=TButton(Sender).caption; //referencing button caption using "Sender"

PROBLEM (I can't figure out how to achieve that with TableGrid, trying to get the RowCount of a Table Grid using the 'Sender'

rowCo:=TGrid(Sender).RowCount - 1;//What should I replace TGrid(Sender) with?

Any Help?
Regards

@thezimguy

Re: [SOLVED] TagbleGrid, Pagination, Footer and Offset

Hello.


rowCo:=TdbStringGridEx(Sender).RowCount - 1;
Dmitry.

20 (edited by thezimguy 2018-08-31 19:15:57)

Re: [SOLVED] TagbleGrid, Pagination, Footer and Offset

DriveSoft wrote:

Hello.


rowCo:=TdbStringGridEx(Sender).RowCount - 1;

This is greeeeeeaaat
Now, it is going to be very simple to create my functions
Thanks Dmitry.

@thezimguy

21 (edited by thezimguy 2018-09-01 08:10:47)

Re: [SOLVED] TagbleGrid, Pagination, Footer and Offset

Again, please how do I get the value/text in the footer of a tableGrid into an editBox
Thanks

@thezimguy

22 (edited by derek 2018-09-01 09:55:06)

Re: [SOLVED] TagbleGrid, Pagination, Footer and Offset

Hi,
If I understand what you're wanting to do correctly, I'd use
form1.edit1.text := form1.tablegrid1.columns[0].footer.caption;
You could also use
form1.edit1.value := form1.tablegrid1.columns[0].footer.formulavalue;
There might be other ways.
Please see attached (lines 56-57 in the script).
Regards,
Derek.

Post's attachments

Attachment icon ranking with footer caption.zip 366.66 kb, 501 downloads since 2018-09-01 

Re: [SOLVED] TagbleGrid, Pagination, Footer and Offset

Hi Derek
Thank you so much
It's good to hear from you.
I really appreciate your help
Regards

@thezimguy

24 (edited by thezimguy 2018-09-01 14:07:30)

Re: [SOLVED] TagbleGrid, Pagination, Footer and Offset

Hello Dmitry, Derek and MVD Users
Please, can you help me on this?
I am trying to mask some columns and footer of the tableGrid.
This is what I have without the mask
https://s6.postimg.cc/kifvfausx/without_Mask.png



This is what i"m getting with the mask only the ones in circle worked for me

TNxNumberColumn(frmPurchase.tGrid.Columns[3]).FormatMask:='#,##0.00';
TNxNumberColumn(frmPurchase.tGrid.Columns[4]).FormatMask:='#,##0.00';
TNxNumberColumn(frmPurchase.tGrid.Columns[5]).FormatMask:='#,##0.00';     
TNxNumberColumn(frmPurchase.tGrid.Columns[5]).Footer.FormatMask:='#,##0.00';

https://s6.postimg.cc/ma8ua76g1/with_Mask.png

Any help will be appreciated
Thank you.

@thezimguy

25 (edited by derek 2018-09-01 20:22:04)

Re: [SOLVED] TagbleGrid, Pagination, Footer and Offset

Hi,
The problem with the 'companyprice' and 'sellingprice' columns is that the fields (I'm guessing) are defined as 'real';  I would change these to 'currency' and make sure that 2 decimal places (the default) is checked.
Please have a look at the script in the attachment which may help. 
In the script, I've added lines to right justify the headings for numeric columns (I just think it looks neater), which may be something you're also interested in doing.
Also, I've added a currency symbol (in this example just to the footer formatting).  Again, it may be something you might want to use.
Regards,
Derek.

Post's attachments

Attachment icon formatting.zip 337.76 kb, 594 downloads since 2018-09-01