Page 1 of 1
how to manipulate record count in homepage?
Posted: 2020-11-13 19:20
by onoehring
Hi,
I need to adjust the value shown as record count in the homepage.

- reccount.png (2.82 KiB) Viewed 2441 times
I have the JS selector path
Code: Select all
document.querySelector("#tablename-tile > div > div > div.btn-group > a:nth-child(1) > span").textContent='MY_VALUE'
The value shows the total number of record in the table - I want it to show only the record count of those matching certain criteria.
Thus I think I will need to combine PHP with JS:
Use PHP to get the count I want and dynamically add this to the JS.
So my question is: Where do I add the code so that injects (or changes the badge contents before displaying the number)?
Thanks already
Olaf
Re: how to manipulate record count in homepage?
Posted: 2020-11-13 19:37
by pbottcher
Hi Olaf,
add the code to the hooks/header-extras.php, check if you are in the index.php page and off you go.
Re: how to manipulate record count in homepage?
Posted: 2020-11-14 08:43
by onoehring
Hi pbötcher,
thank you. It worked like a charm.
The code I placed in header-extras:
Code: Select all
$position = stripos($_SERVER['REQUEST_URI'], 'index.php');
if ($position === 1){
//we are on INDEX / MAIN / LOGIN
} else {
//we are SOMEWHERE ELSE
}
?>
Olaf
Re: how to manipulate record count in homepage?
Posted: 2020-11-14 09:24
by onoehring
Hi again,
actually this does not work as expected: If I have another user with different table permissions, the JS path seems to change and my code thus fails to update a badge that does not exist on another table
Olaf
Re: how to manipulate record count in homepage?
Posted: 2020-11-14 09:35
by onoehring
Hi,
I suppose the reason is, that as admin I have an extra "+" on the button, so it's rendered as a button-group. The other user however can not add to that table, so there is no "+" and no button group.
Olaf
Re: how to manipulate record count in homepage?
Posted: 2020-11-14 09:48
by onoehring
Hi
just reporting back. Problem seems to be solved.
I am checking the permissions of the logged in user. If he has INSERT permission, I need another JS path than without.
Code: Select all
<?php//Check user permission on table Jobs. If user can add to jobs it's a button group
$permission = getTablePermissions('ecomo_jobs');
if ($permission['insert'] != 0) {
?>document.querySelector("#tablename-tile > div > div > div.btn-group > a:nth-child(1) > span").textContent='<?php echo $myValue; ?>';
<?php
} else {
?>document.querySelector("#tablename-tile > div > div > a > span").textContent='<?php echo $myValue; ?>';
<?php
}
?>
Not: This code goes into the are of the position check which says "//we are on INDEX / MAIN / LOGIN" and, as it's JS, it needs to be placed inside <script>...</script> tags (which I do not show here as there is more code).
Thanks again.
Olaf