function child_records_config

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
User avatar
zibrahim
Veteran Member
Posts: 137
Joined: 2020-01-28 18:30
Location: Malaysia

function child_records_config

Post by zibrahim » 2022-09-04 00:59

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.
Zala.
Appgini 24.10.1579, MacOS 14.3.1 Windows 11 on Parallels.

AhmedBR
AppGini Super Hero
AppGini Super Hero
Posts: 327
Joined: 2013-09-19 10:23

Re: function child_records_config

Post by AhmedBR » 2022-09-04 12:06

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.
AppGini 22.14 - xampp 3.3.0 - PHP 7.4.30 - Summary reports - Calendar - Mass update - Messages - AppGiniHelper

AhmedBR
AppGini Super Hero
AppGini Super Hero
Posts: 327
Joined: 2013-09-19 10:23

Re: function child_records_config

Post by AhmedBR » 2022-09-04 12:12

To do what you want there is a topic on how to increase to more than 10:

viewtopic.php?t=2245
AppGini 22.14 - xampp 3.3.0 - PHP 7.4.30 - Summary reports - Calendar - Mass update - Messages - AppGiniHelper

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

Re: function child_records_config

Post by jsetzer » 2022-09-04 13:29

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; }); });
}
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: function child_records_config

Post by zibrahim » 2022-09-04 14:36

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.
Zala.
Appgini 24.10.1579, MacOS 14.3.1 Windows 11 on Parallels.

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

Re: function child_records_config

Post by jsetzer » 2022-09-04 15:45

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.
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
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1814
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: function child_records_config

Post by jsetzer » 2022-09-04 16:30

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);
}
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: function child_records_config

Post by zibrahim » 2022-09-05 23:48

Thank you very much Jan !!
Zala.
Appgini 24.10.1579, MacOS 14.3.1 Windows 11 on Parallels.

Post Reply