Page 1 of 1
function child_records_config
Posted: 2022-09-04 00:59
by zibrahim
Hi there,
Anyone knows how to use this child_records_config function in the __global hooks?
I want to change the number of records in the child table from the default 10 to 20.
I understand that this function is newly added in 22.14
Appreciate if someone can share the syntax as I couldn't find it in the forum or the appgini website.
Thanks.
Re: function child_records_config
Posted: 2022-09-04 12:06
by AhmedBR
Hi Zibrahim,
Take a look at this link:
https://bigprof.com/appgini/help/advanc ... rds_config
I do not think it will help changing 10 to 20, might be wrong though.
Re: function child_records_config
Posted: 2022-09-04 12:12
by AhmedBR
To do what you want there is a topic on how to increase to more than 10:
viewtopic.php?t=2245
Re: function child_records_config
Posted: 2022-09-04 13:29
by jsetzer
Hi Zibrahim, sure you can:
Code: Select all
function child_records_config($childTable, $childLookupField, &$config)
{
$rpp = 20;
array_walk($config, function (&$t) use($rpp) { array_walk($t, function (&$cn) use($rpp) { $cn["records-per-page"] = $rpp; }); });
}
Re: function child_records_config
Posted: 2022-09-04 14:36
by zibrahim
Thanks Jan. It works flawlessly!
I believe it is not as straight forward like the init function, right?
Need to figure out how to set some parent and child table combinations with the specific records per page value...
Thanks again.
Re: function child_records_config
Posted: 2022-09-04 15:45
by jsetzer
It is straight forward.
$config
contains settings for all tables, not just for one table (as in hooks/TABLENAME.php
/ TABLENAME_init(...)
-function).
You can modify the code above and do changes for certain tables/fields, only.
Re: function child_records_config
Posted: 2022-09-04 16:30
by jsetzer
Code: Select all
function child_records_config($childTable, $childLookupField, &$config)
{
// example:
// partners.id <---- contacts.partner_id
changeRecordsPerPage($config, "contacts", "partner_id", "partners", 1);
}
Code: Select all
function changeRecordsPerPage(&$config, $tn, $cn, $parentTn, $recordsPerPage = 20)
{
$cfg = $config[$tn][$cn];
if (!$cfg) die("Not found: {$tn}.{$cn}");
if ($cfg["parent-table"] != $parentTn) die("Parent table mismatch");
$config[$tn][$cn]["records-per-page"] = max(1, $recordsPerPage);
}
Re: function child_records_config
Posted: 2022-09-05 23:48
by zibrahim
Thank you very much Jan !!