Hide Published Table
-
I was wondering if it’s possible to completely hide a table (using short-code from data publisher) when there’s no data available in it?
-
Hi @samonpress,
I think you can do that. You can write a JavaScript function to handle this action based on your search results. The table is shown inside a div. You can hide the div or the table in your css on startup. You then have to check if the table contains any data. If so, you can show the table.
If you do it the other way round (show the table on startup and hide if no data was found) the user will see an empty table before it is hidden.
I’m just wondering where to put your JavaScript function. You can try to execute it when the page is loaded, but I’m afraid that to early. At that moment you might always find an empty table. Maybe add a dealy?
@anyoneelse an idea…?
Please let me know how you continue…
Best regards,
PeterThank you for the response Peter!
I thought of solving it by checking if the user is logged in, if yes then show table else hide. (Because if Yes – then there must be some data).
I was trying to use Table Option (advance) within Data Publisher. From another topic I learned that I’ve to disable JSON validation and toggled it to textarea without JSON validation to avoid the error message.
For the beginning I am only trying to hide the table in advance option but nothing seems to be happening. Here’s the code and I’m sure I might be doing something wrong. Can you please help.
$(document).ready(function() { $("#tdwholesome21_wrapper).hide(); });-
This reply was modified 5 years, 8 months ago by
samonpress.
Hi @samonpress,
I’ve been experimenting a little and found a solution. Please enter this JSON in your table options advanced column:
{
“initComplete”: “function( settings, json ) { if (json.recordsTotal==0) { jQuery(‘#tdwholesome21_wrapper’).hide(); } }”
}The JS function will be executed after your initial query. When no rows are found (json.recordsTotal==0) the wrapper div is hidden. I would advise to hide the wrapper div (set style display:none) and make it visible when rows are found. Otherwise the user will first see your table appear and then disappear.
Allow me to add few notes:
– The content of the table options advanced column must be valid JSON
– You cannot enter JS code in the table options advanced column directly
– You can only use JS code in the table options advanced column for eventsHere is some background information:
https://datatables.net/reference/option/
https://datatables.net/reference/option/initCompletePlease let me know if this solves your problem!
Best regards,
PeterHi Peter!
I tried with this code in Table Options advance column. It gives an error as follows:
Parse Error on Line 1:
{“initComplete”:
_^
Expecting ‘STRING’, ‘}’, got ‘undefined’Sorry @samonpress! The quotes are changed when you post a message. I had to put the JSON in a code tag. Please try this:
{ "initComplete": "function( settings, json ) { if (json.recordsTotal==0) { jQuery('#tdwholesome21_wrapper').hide(); } }" }Sorry,
Peter -
This reply was modified 5 years, 8 months ago by
The topic ‘Hide Published Table’ is closed to new replies.