Okay
  Public Ticket #3050611
JSON table issue
Closed

Comments

  • JOHN started the conversation

    Folks... I'd like to share an issue I had had getting JSON tables to work. The work is being done under an NDA so I cannot share a URL, or otherwise go into too much detail.

    I have JSON files that are templates of JSON returned by a serverless function (e.g. AWS Lambda). In trying to generate a table from the JSON I kept getting the error saying no table rows were found, although I know the JSON format (array) is correct.

    I am integrating with WP Forms, and hooking into an action once the form is complete. I take the uploaded file and post it to the serverless function. The function returns the JSON which then populates the table.

    In order to accomplish this, I have a child theme (Enfold is the parent). The stuff I am doing really belongs in a custom plugin, but for now it is in the functions.php file in my child theme.

    Once I hook into the WP Forms process complete action, I get the URL of the file I uploaded and save it to a session variable. This requires I start the session. The WP Forms hook does a redirect to the page where I show the wpDatatable. I hooked into the wpdatatables_filter_json() filter, which gets the template JSON. I look up the URL from session state, read in the file, post it to the serverless function (wp_remote_post) and then swap in the JSON returned by the function to show the data.

    Figuring out to swap in the JSON was one of my challenges. Hooking into that filter solved that. The other problem took a lot longer. When I use the plugin to create the table. for some reason my functions.php is being processed in an unexpected fashion. I am pretty sure the session variables are where the problem lies, based on turning debugging on and seeing the warnings/issues. For some reason this was preventing the plugin from executing its code to get the JSON file (the template) in order to create the table. I kept getting the error saying there were no table rows...

    So I simply added ".temp" to "function.php" in my child theme so it would not be loaded/processed when working in the admin back end. Once I did that, the plugin read the JSON file correctly and built out the table. Once I styled it and saved, I renaming the function.php.temp back to function.php.

    It all works now, with the filtering approach described above providing the data.

    So if anyone is trying to build a table from a JSON file and gets the error saying there are no rows, first make sure your JSON is correct (it should be an array of identical objects, identical at least in terms of the attribute/column names). If the problem persist and you have a child theme with functions/header/footer files, try renaming them temporarily and then try to create the table.

    For the TMS team, if there is a way to suppress execution of child theme php files when in the plugin's UI, that would be awesome, For now, I have a couple other tables to develop, but at least I have a workaround.

    Hope this helps...

    Oh, also: Check out the "BugFu" plugin... it is a terrific tool to spit info to the browser console for troubleshooting.

  •  2,503
    Aleksandar replied

    Hello John.

    Thank you very much for this! I'm sure it will come in handy for a lot of customers. The ticket was already forwarded to our developers yesterday, I just didn't have the time to respond to it.

    They will look into suppressing the execution of child theme PHP files, and I personally want to thank you for the BugFu recommendation. I have no doubt it will come in handy today!

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia 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