Count of child table records in the parent table view

The recommended method of customizing your AppGini-generated application is through hooks. But sometimes you might need to add functionality not accessible through hooks. You can discuss this here.
Post Reply
alvaguti
Posts: 2
Joined: 2021-03-03 12:34

Count of child table records in the parent table view

Post by alvaguti » 2021-03-03 13:54

I want to know if I can display the count of child records in the parent table view.
Something similar to the count you can display in the child table tab.

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Count of child table records in the parent table view

Post by pbottcher » 2021-03-04 07:24

How shall this look like?
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Count of child table records in the parent table view

Post by jsetzer » 2021-03-04 08:39

If you mean something like this ...

chrome_PE4zRlnhbu.png
chrome_PE4zRlnhbu.png (8.96 KiB) Viewed 2724 times

... then ...
  1. Create a new calculated field in your master-table, integer, readonly
  2. On “Calculated field” tab, check "[X] Automatically calculate the value…"
  3. Place the following code into the textarea:

    Code: Select all

    SELECT concat('<span class="badge">', count(*), '</span>' )
    FROM `TABLENAME_CHILDTABLE`
    WHERE `COLUMNNAME_LOOKUPFIELD`= '%ID%'
    
  4. In line 2,replace TABLENAME_CHILDTABLE by the name of your child-table
  5. In line 3 replace COLUMNNAME_LOOKUPFIELD by the column name of the lookup field in your child-table which is referencing your master table
  6. Generate your application and (re-) load the table view of master table
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

alvaguti
Posts: 2
Joined: 2021-03-03 12:34

Re: Count of child table records in the parent table view

Post by alvaguti » 2021-03-06 11:55

Thank you Jsetzer. works fine.

User avatar
zibrahim
Veteran Member
Posts: 137
Joined: 2020-01-28 18:30
Location: Malaysia

Re: Count of child table records in the parent table view

Post by zibrahim » 2021-03-07 01:36

Hi Jan,
Correct me if I am wrong, in your suggested steps...
the calculated field should not be integer if you are putting the "<span class="badge">.... right?
It should be VarChar or text field.

Thanks.
Zala.
Appgini 24.10.1579, MacOS 14.3.1 Windows 11 on Parallels.

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Count of child table records in the parent table view

Post by jsetzer » 2021-03-07 08:50

Hi, without having checked this, I think you are right, thanks a lot for pointing this out and thank you for all your contributions!

Reason: when answering the request, in first step I was only displaying count and so integer was perfect. In a follow up step I have added that UI badge using concat and did not change the data type. My fault. Anyway: it still works in UI for displaying the badge, which was the requirement. It will not store actual count in DB.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

User avatar
zibrahim
Veteran Member
Posts: 137
Joined: 2020-01-28 18:30
Location: Malaysia

Re: Count of child table records in the parent table view

Post by zibrahim » 2021-03-08 12:41

no worries Master Jan....
Zala.
Appgini 24.10.1579, MacOS 14.3.1 Windows 11 on Parallels.

Post Reply