I'm trying to show a table from an external JSON source. I need the data displayed to be filtered hard by the logged in user, %CURRENT_USER_LOGIN%, which is part of the data in one column. How can I do that?
So I basically have one datasource with multiple users data, and I need to filter the data so users can only see their own.
Thank you for taking the time to help me with this.
You will not be able to achieve this with the free/Lite wpDataTables, but with Premium version you would have these Advanced Filtering options as explained in this Documentation.
So i will show you an example how you would to this with the full/premium wpDataTables.
We have a workaround for non-editable ( linked to a file source) tables,
to restrict only showing the rows for the currently logged-in user.
I will show you an example with another Placeholder "Current User ID", but you will be able to use the same way, just change the Placeholder to "%CURRENT_USER_LOGIN%" .
And this is an example using Excel as source File, but you can do the same with a JSON Source File.
-
- First, you would have to add a custom "user_id" column on the source Excel side ( in your case JSON file), which you can hide if needed in our plugin from the front-end.
We will add a predefined filter value to it, using a Place Holder "Current User ID";
- Check that the filter type is set as "Text", as shown on this screenshot.
- Here is how an example table linked to a source file looks before we make any changes, with visible filters above the table.
And now, when we set the pre-filter, with Administrator logged in ( In our case, the user ID is 1), we only see rows matching that user ID.
- The user_ID filter is still visible, which means, if someone changes/deletes this value, they could see the whole table.
We will hide it from the front-end with some custom CSS added in the "Customize" section of the main table settings.
- It should be easy to do, depending on your knowledge of HTML and CSS.
You have to find the correct selector using the browser inspector tool, add the style "display:none" property to it, and it will disappear from the front-end.
On our example table, the custom CSS is :
#table_1_5_filter_sections {
display:none; }
- Now, the user_ID filter is gone from the front-end.
- Optionally, you can hide the user_id column from the front-end, if needed, either using the column settings tab or the "column list" button from the back end Admin area.
- If you need more details about this, don't hesitate to contact us further.
Here you can see the full list of all available Placeholders for filtering;
Here you can see more about all Advanced Filters for Premium version;
And i just wanted to point out that you can try wpDataTables before purchasing
on our sandbox Demo sites ( you can find links for the main plugin Demo,
as well as add-on Demos, in my signature),
and there is a 15-day money-back guarantee period,
so if you purchase the plugin, you can safely fully test it out, and if it doesn't fit your needs you can request and receive a refund in that period. ( same goes for all plugins and add-ons)
Hi,
I'm trying to show a table from an external JSON source. I need the data displayed to be filtered hard by the logged in user, %CURRENT_USER_LOGIN%, which is part of the data in one column.
How can I do that?
So I basically have one datasource with multiple users data, and I need to filter the data so users can only see their own.
Thank you for taking the time to help me with this.
Hi Janus,
Thanks for showing interest in our Plugin.
You will not be able to achieve this with the free/Lite wpDataTables, but with Premium version you would have these Advanced Filtering options as explained in this Documentation.
So i will show you an example how you would to this with the full/premium wpDataTables.
You can also test this solution on our Demo Site here.
-
We have a workaround for non-editable ( linked to a file source) tables,
to restrict only showing the rows for the currently logged-in user.
I will show you an example with another Placeholder "Current User ID", but you will be able to use the same way, just change the Placeholder to "%CURRENT_USER_LOGIN%" .
And this is an example using Excel as source File, but you can do the same with a JSON Source File.
-
- First, you would have to add a custom "user_id" column on the source Excel side ( in your case JSON file), which you can hide if needed in our plugin from the front-end.
We will add a predefined filter value to it, using a Place Holder "Current User ID";
- Check that the filter type is set as "Text", as shown on this screenshot.
- Here is how an example table linked to a source file looks before we make any changes, with visible filters above the table.
And now, when we set the pre-filter, with Administrator logged in ( In our case, the user ID is 1), we only see rows matching that user ID.
- (If you need more detailed information about using Place Holders in wpDataTables, here is our documentation about that https://wpdatatables.com/documentation/table-features/using-placeholders/);
- The user_ID filter is still visible, which means, if someone changes/deletes this value, they could see the whole table.
We will hide it from the front-end with some custom CSS added in the "Customize" section of the main table settings.
- It should be easy to do, depending on your knowledge of HTML and CSS.
You have to find the correct selector using the browser inspector tool, add the style "display:none" property to it, and it will disappear from the front-end.
On our example table, the custom CSS is :
- Now, the user_ID filter is gone from the front-end.
- Optionally, you can hide the user_id column from the front-end, if needed, either using the column settings tab or the "column list" button from the back end Admin area.
- If you need more details about this, don't hesitate to contact us further.
Here you can see the full list of all available Placeholders for filtering;
Here you can see more about all Advanced Filters for Premium version;
And i just wanted to point out that you can try wpDataTables before purchasing
on our sandbox Demo sites ( you can find links for the main plugin Demo,
as well as add-on Demos, in my signature),
and there is a 15-day money-back guarantee period,
so if you purchase the plugin, you can safely fully test it out, and if it doesn't fit your needs you can request and receive a refund in that period. ( same goes for all plugins and add-ons)
Let me know if you have any additional questions.
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