Page 1 of 1
Count of child table records in the parent table view
Posted: 2021-03-03 13:54
by alvaguti
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.
Re: Count of child table records in the parent table view
Posted: 2021-03-04 07:24
by pbottcher
How shall this look like?
Re: Count of child table records in the parent table view
Posted: 2021-03-04 08:39
by jsetzer
If you mean something like this ...

- chrome_PE4zRlnhbu.png (8.96 KiB) Viewed 3834 times
... then ...
- Create a new calculated field in your master-table, integer, readonly
- On “Calculated field†tab, check "[X] Automatically calculate the value…"
- Place the following code into the textarea:
Code: Select all
SELECT concat('<span class="badge">', count(*), '</span>' )
FROM `TABLENAME_CHILDTABLE`
WHERE `COLUMNNAME_LOOKUPFIELD`= '%ID%'
- In line 2,replace TABLENAME_CHILDTABLE by the name of your child-table
- In line 3 replace COLUMNNAME_LOOKUPFIELD by the column name of the lookup field in your child-table which is referencing your master table
- Generate your application and (re-) load the table view of master table
Re: Count of child table records in the parent table view
Posted: 2021-03-06 11:55
by alvaguti
Thank you Jsetzer. works fine.
Re: Count of child table records in the parent table view
Posted: 2021-03-07 01:36
by zibrahim
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.
Re: Count of child table records in the parent table view
Posted: 2021-03-07 08:50
by jsetzer
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.
Re: Count of child table records in the parent table view
Posted: 2021-03-08 12:41
by zibrahim
no worries Master Jan....