Hide fields select box

Got something cool to share with AppGini users? Feel free to post it here!
Post Reply
hubert
Veteran Member
Posts: 50
Joined: 2018-12-06 22:32

Hide fields select box

Post by hubert » 2018-12-19 08:13

Hi,

I'm quite annoyed with the field selector which is on the table view, upper right of the page.
I do not want some fileds of the table to appear to logged (or not) users, only admins.
But, as I can select the fields, it's alaways possible to make a new selection on hidden fields there .. and I can't accept this
Any key ? May be a javascript routine ?

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

Re: Hide fields select box

Post by jsetzer » 2018-12-19 21:57

Hi Hubert,

hiding the toggle-column-button depending on the current user or group using hooks only is quite complicated. You need to pass current member information from PHP to Javascript or Javascript needs to call a serverside PHP script via AJAX to find out who's logged in.

To hide the column-toggle-button for all users, you can try one of these simple jQuery solutions:

1. Hide button in all table views

Place the following code in hooks/header-extras.php:

Code: Select all

<!-- hooks/header-extras.php -->
<script>
    $j(function() {
      $j('button.tv-toggle').hide();
    });
</script>

2. Hide button in one table view

Create or open the file hooks/TABLENAME-tv.js and put the following code there:

Code: Select all

    $j(function() {
      $j('button.tv-toggle').hide();
    });


From my point of view the toggle-button is very useful, because every single user can reduce the amount of information to the minimum s*he needs. I always use the "Hide in table view" checkbox in AppGini to definately hide columns.

By the way: My Toggle-panel looks a bit different than the default style:

Styled:
chrome_2018-12-19_22-50-33.png
chrome_2018-12-19_22-50-33.png (12.26 KiB) Viewed 3039 times
Default:
2018-12-19_22-53-48.png
2018-12-19_22-53-48.png (11.22 KiB) Viewed 3039 times

Regards,
Jan
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

sacgtdev
Veteran Member
Posts: 75
Joined: 2020-06-10 11:14

Re: Hide fields select box

Post by sacgtdev » 2021-07-07 03:56

Is there a way to pre-select(default) a few fields in the toggle so that every time the page loads, only the pre-select(default) field was being shown in the table view?

Any code?

Thank you.

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

Re: Hide fields select box

Post by jsetzer » 2021-07-08 06:51

(1) You can check "[X] Hide in table view" but this will hide them for everyone
(2) Have a look at localstorage in browser's dev-tools. There are entries like "columns_TABLENAME_view" which can be modified using Javascript. I never did this, but it should work if you set values according to your needs before AppGini reads those settings.
Attachments
firefox_sSKUjTjtQa.png
firefox_sSKUjTjtQa.png (23.69 KiB) Viewed 2050 times
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

sacgtdev
Veteran Member
Posts: 75
Joined: 2020-06-10 11:14

Re: Hide fields select box

Post by sacgtdev » 2021-07-08 09:22

I try it on the browser console:

Code: Select all

window.localStorage.removeItem('columns-contact_view');

const field = {"contacts-department_id":true,"contacts-name":true,"contacts-email":true,"contacts-phone":true}

window.localStorage.setItem('columns-contact_view', JSON.stringify(field));
It works and will unset and reset the columns-contact_view. I try it on contact.php in the hooks folder:

Code: Select all

$footer=<<<EOT
<script>
			\$j(function() {
				
				window.localStorage.removeItem('columns-contact_view');
			
				const field = {"contacts-department_id":true,"contacts-name":true,"contacts-email":false,"contacts-phone":false}
			
				window.localStorage.setItem('columns-contact_view', JSON.stringify(field));
					
					


});
</script>;
EOT;
It somehow works but need to hit a refresh again to reflect the changes. I think it is because the native javascript loaded first. Any workarounds?

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

Re: Hide fields select box

Post by jsetzer » 2021-07-08 12:41

Did you try in header-extras.php?
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

sacgtdev
Veteran Member
Posts: 75
Joined: 2020-06-10 11:14

Re: Hide fields select box

Post by sacgtdev » 2021-07-09 00:48

Just for sharing. It works in certain extents.
But, if there is changes on toggle fields, it will not persist over the page or refresh.

I guess the cookies will be re-write for every refresh or page navigation.

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

Re: Hide fields select box

Post by jsetzer » 2021-07-09 06:42

I think if the localStorage value does not exist, you should write your default value, otherwise don't touch it.
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

sacgtdev
Veteran Member
Posts: 75
Joined: 2020-06-10 11:14

Re: Hide fields select box

Post by sacgtdev » 2021-07-10 04:20

This code shall works at header-extras.php

Code: Select all


<script>
			\$j(function() {
				if (localStorage.getItem("columns-contact_view") === null){
				
					const field = {"contacts-department_id":true,"contacts-name":true,"contacts-email":false,"contacts-phone":false}
			
					window.localStorage.setItem('columns-contact_view', JSON.stringify(field));
				
				}
					
					


});
</script>;


Post Reply