Okay
  Public Ticket #2290608
Displaying table from PHP code
Closed

Comments

  • Mark Williams started the conversation

    Is it possible to expose a wpDataTables object from code (a plugin I am developing) and then populate that table with data from that same code (a serialized array, for example)?

    As a starter, I tried using do_shortcode (with the appropriate shortcode for a table I created manually) but that doesn't result in any output. I used this, for example...

                do_shortcode('[wpdatatable id=1]');

    If I create a wpDataTable object from Gutenburg I can see/edit that table OK. But do_shortcode results in nothing being displayed.

    I also tried adding the simple shortcode (outside of my <?php ?> elements) but that also renders nothing.

    For context, I am planning to create a plugin for us in my own business to help manage data via the admin UX. So, I am hoping I can a) create a table in wpDataTables (empty) b) initialize the data in the table from my PHP code and b) display that data. Later I may wish to support editing, but that is a secondary priority right now.

    Thank you.

  •  2,514
    Aleksandar replied

    Hello Mark

    Thank you for your purchase.

    Are you using this on back-end pages?

    Generally speaking, the tables cannot be empty. You can create 1 row with some user and then hide it. What you're looking for to achieve is considered customization of the plugin, and it is not included in the provided support, which only refers to advice.

    For these actions we've developed hooks, so you can find which ever suits you best, so you can use it and replace the data in the table with your own data, and return it in the format passed by that hook.

    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

  • Mark Williams replied

    Thank you for the response, Aleksandar. I am comfortable looking at hooks to drive the component. However, before I get that far I want to verify one aspect of your comment.

    To test this I have created a single table and manually added a row, using the wpDataTables admin UX. That row is there specifically to allow me to test each step and how I can present this, before i start looking at hooks, etc.

    My problem is that even with this row manually entered into the table, I still cannot get it to show. For example, within my PHP I have the following...

                do_shortcode( '[wpdatatable id=1]' );

    The table fails to render render. Again, to reiterate, this is just trying to display a regular, table with a single row, created with the wpDataTables admin UX.

    if I create a post and add the shortcode in the body of that post - as opposed to embed it in HTML-rendering PHP - the table renders OK, with the single record it has.

    So, stepping back, if I merely want to render a static table from PHP, how can I do that?

    Thank you.

  • Mark Williams replied

    Sorry - missed one of your questions. Yes, this is for display on backend admin pages.

    My guess and hope is that if I can figure out, with your help, how to get the table to render programmatically (from PHP, for the initial display of a table with a single, dummy row) then I can use hooks to manage the data thereafter. So if I can just get past that point I'd be looking pretty good moving forward.

    That''s the hope, at least :)

  •  2,514
    Aleksandar replied

    Hi again Mark

    Sorry for the late response.

    At the moment, you can only create a table through our interface. Dynamically creating tables is not possible at this time. It is possible to change the data, but not the structure itself.

    Unfortunately, what you're asking for is only available as a custom solution, which is not included in the provided support for the plugin, so I can't help you with that.

    We do offer customization on paid basis, but our developers are very busy at the moment, working on some priority tasks and fixing bugs and issues with our plugins, so they won't be having the time for custom work in near future.

    But we can recommend these services for customization:

    https://codeable.io/?ref=l1TW1

    https://wpkraken.io/?tms-plugins

    They do develop such solutions, so can you please send your inquiry to them?


    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

  • Mark Williams replied

    Thank you for the response, Aleksandar. I do think I may have done a poor job of explaining my scenario here. So let me add some more detail and hopefully you can point me in the right direction.

    My question here is only about initializing the DATA within a table. I have no problem creating the "the table schema (columns, etc) via the admin UX you provide. But when my admin page is loaded I want to populate that table with data that confirms to that table schema, from a PHP function.

    I understand and accept that I can't change the layout of the table from PHP and that isn't a problem for me. So, stepping back, assuming I have a table already created, how can I configure the data for this from my PHP plugin? I am comfortable with actions/filters but I haven't seen anything in the docs that point me towards this, though I suspect I am just missing this somehow.

    Thank you again.

  •  471
    Isidora replied

    Hi Mark,

    Aleksandar is on vacation and I will help you out.

    As Aleksandar explain you there are filters in our docs that you can use depends on from which table tape you create table:

    wpdatatables_filter_mysql_query( $query, $tableId )
    This filter is applied to the MySQL query before it is sent to MySQL server.

    $query is the query text

    $tableId is the table identifier from the MySQL table (wp_wpdatatables).


    wpdatatables_filter_json( $json, $tableId )
    This filter is applied to the JSON string before building a table based on it.

    $json is the JSON string itself

    $tableId is the table identifier from the MySQL table  (wp_wpdatatables).


    wpdatatables_filter_simplexml( $simpleXmlObject, $tableId )
    This filter is applied to the parsed XML (SimpleXML library is used for parsing the XML files), a SimpleXML object, before creating a table based on it.

    $simpleXmlObject is the SimpleXML object

    $tableId is the table identifier from the MySQL table  (wp_wpdatatables).


    wpdatatables_filter_excel_array( $parsedArray, $tableId, $filePath )
    This filter is applied to the array which is generated based on the Excel file. First each excel file is parsed to the array, which you can later modify with this filter.

    $parsedArray is the array which is parsed out of the Excel file

    $tableId is the table id identifier from the MySQL table (wp_wpdatatables)

    $filePath is the path to Excel file.


    With those filters you can overwrite data from source and return it as you need.

    Best regards.

    Kind Regards, 

    Isidora Markovic

    wpDataTables: FAQFacebookTwitterFront-end and back-end demoDocs

    Amelia: FAQFacebookTwitter |  Amelia demo sites | Docs

    You can try our wpDataTables add-ons before purchase on these sandbox sites:

    Powerful FiltersGravity Forms Integration for wpDataTablesFormidable Forms Integration for wpDataTables