If the dependency is a user role, for example, we could make it work.
Here is an example we made some time ago.
If I have this table:
This is a manual table which has manually entered IDs from wp_users and roles from wp_usermeta:
So, then I go to create an SQL query based table which will display entries based on user roles using this query:
SELECT new_table.id AS ID,
new_table.role AS Role,
new_table.product AS Product,
new_table.amount AS Amount
FROM wp_wpdatatable_6 AS new_table
JOIN wp_usermeta AS new_table_1
ON new_table_1.user_id = %CURRENT_USER_ID%
AND new_table_1.meta_value LIKE CONCAT('%', new_table.role, '%')
When I'm logged in with user ID = 1 , I see this:
When I'm logged in with user ID = 4, I see the same thing. And when I'm logged in as one of the subscribers, I can only see the rows where role = subscriber:
The only difference is that as subscriber I don't have access to back-end, so this confirms it is working on both front and back.
So, we're only left with hiding unnecessary columns, adding names, and so on.
Hope this helps.
If you need more information, please contact us further. Thanks
I am still looking to give you the possible solutions to do this.
If you can give me a bit more time, I should be able to get additional advice from the devs tomorrow and gonna advise you what might be available from the functionalities, don't wanna give you partial information.
- Unfortunately, we can't create a solution as intended, in terms of one dynamic table having columns that can hide or show depending on a user role.
- The solution we can suggest for this functionality, is creating multiple tables on multiple pages.
You can have one main "source table" that holds all the data and columns.
It could be a Manual type, or SQL based (has to be created in the database), and then create separate tables from it by an SQL Query, each query can pull only the columns you need for a certain role. (an Admin can have access to the main/source table).
;
- In order to limit access to certain pages and tables, since wpDataTables can't do that, you can install a membership plugin, and set up which roles are restricted/allowed to view certain pages.
So, for example, if table 1 is for the Subscriber role, limit that page just for them, a second table just for editors, and so on; depending on what you need to achieve, which you can set up with a membership plugin.
- Hopefully, that makes sense. If I didn't explain something clearly enough, of course, we will be here, don't hesitate to reach out to us. Thanks.
Is there a way to Show/Hide Column Based on WP User Role.
1. Admin can see all columns
2. User can see columns 1, 2, 5, & 6 (3 & 4 are hidden)
Hi, Joshua
Thanks for showing interest in our plugin
-
If the dependency is a user role, for example, we could make it work.
Here is an example we made some time ago.
If I have this table:
This is a manual table which has manually entered IDs from wp_users and roles from wp_usermeta:
So, then I go to create an SQL query based table which will display entries based on user roles using this query:
When I'm logged in with user ID = 1 , I see this:
When I'm logged in with user ID = 4, I see the same thing. And when I'm logged in as one of the subscribers, I can only see the rows where role = subscriber:
The only difference is that as subscriber I don't have access to back-end, so this confirms it is working on both front and back.
So, we're only left with hiding unnecessary columns, adding names, and so on.
Hope this helps.
If you need more information, please contact us further. Thanks
Kind Regards,
Miloš Jovanović
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables
Thank you for such a rapid response.
It appears like in your example the rows are capable of being hidden - which is great.
I am wondering if it would be possible to hide specific columns in the table?
Sorry for such a long wait time, Joshua.
I am still looking to give you the possible solutions to do this.
If you can give me a bit more time, I should be able to get additional advice from the devs tomorrow and gonna advise you what might be available from the functionalities, don't wanna give you partial information.
Thank you for your patience.
Kind Regards,
Miloš Jovanović
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables
- Hi, Joshua
I have conclusive information now regarding this.
- Unfortunately, we can't create a solution as intended, in terms of one dynamic table having columns that can hide or show depending on a user role.
- The solution we can suggest for this functionality, is creating multiple tables on multiple pages.
You can have one main "source table" that holds all the data and columns.
It could be a Manual type, or SQL based (has to be created in the database), and then create separate tables from it by an SQL Query, each query can pull only the columns you need for a certain role. (an Admin can have access to the main/source table).
;
- In order to limit access to certain pages and tables, since wpDataTables can't do that, you can install a membership plugin, and set up which roles are restricted/allowed to view certain pages.
So, for example, if table 1 is for the Subscriber role, limit that page just for them, a second table just for editors, and so on; depending on what you need to achieve, which you can set up with a membership plugin.
- Hopefully, that makes sense. If I didn't explain something clearly enough, of course, we will be here, don't hesitate to reach out to us. Thanks.
Kind Regards,
Miloš Jovanović
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables