Okay
  Public Ticket #2699253
From wpDataTable, to modal, to post/page
Closed

Comments

  •  4
    Sebastian Gendry started the conversation

    Hello,

    (How) Is it possible to dynamically link to an entry post/page from inside a modal, or can it only be one or the other (users either open a modal OR open a post/page)?

    Thank you

  •  2,498
    Aleksandar replied

    Hello Sebastian

    I don't know if I understood this correctly.

    You want an entry from the table to appear in the MD modal as a hyperlink that would take the visitor to the specific post or page? That link would be dynamically generated by the content of the cell, right?

    If that's true, you could use the CONCAT function, like this:

    SELECT column1,
            column2,
            CONCAT('<a href="www.yourwebsite.com/page1/',yourTable.column3,'">',yourtable.column3,'</a>') AS Hyperlink
    FROM yourTable
    

    This will create a hyperlink to www.yourwebsite.com/page1/value1 if there's "value1" entered as cell data in column3. On another row, it could be www.yourwebsite.com/page1/value2 if there's "value2" in the cell, and so on.

    So, this would be a hyperlink which could be shown in the modal, and it would take the user to the respective page.

    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

  •  4
    Sebastian Gendry replied

    Hello Aleksandar,

    This is a perfect solution for what I need, but I do not understand how to implement that code.

    What do my columns have to do with the modal? Which one do I need to use to replace the yourTable.column3  in the example below, so that the hyperlink displays in the modal?

    CONCAT('<a href="www.yourwebsite.com/details-page/',yourTable.column3,'">',yourtable.column3,'</a>') AS Hyperlink
    FROM yourTable

    Please clarify. Thank you!

    Right now here is my SQL Query:

    SELECT ssg_main.`Nr`,
           ssg_main.`SCode`,
           ssg_main.`LSCode`,
           ssg_main.`Name Of The Game`,
           ssg_main.`Summary`,
           ssg_main.`Group Age`,
           ssg_main.`Group Size`,
           ssg_main.`Size Of Play Area`,
           ssg_main.`Intention`,
           ssg_main.`Step`,
           ssg_main.`Laughter Step`,
           ssg_main.`Duration`,
           ssg_main.`Exertion`,
           ssg_main.`Social Distancing`,
           ssg_main.`Game Description`,
           ssg_main.`id`
    FROM ssg_main

    FYI, I like the master-detail popup because it's a quick way to see important information. Its major limitations however is that 1. users can't print it, and 2. I can't add videos in there otherwise this seriously impacts the page load time for larger datasets (if there is a way to do some lazy loading for the videos in the modal please let me know how this works).

  •  2,498
    Aleksandar replied

    Hi again Sebastian

    Since Master Detail is actually using data from the table, you would need to create a column where data would be saved in hyperlinks.

    So, you would use the CONCAT function, to append the partial URL to the value of a column.

    Do you actually have pages that would be used in the URL? For example, if your ID column has 1, 2, 3, 4, 5, and you have pages:

    www.yourwebsite.com/pageid=3

    You can use the concat function like this:

    CONCAT('<a href="www.yourwebsite.com/pageid=',ssg_main.id,'">',ssg_main.id,'</a>') AS Hyperlink
    FROM yourTable

    Side note: when you're pulling data from one table in a query, there's no need to include the table's name before column names, and there's no need to use accent graves ( ` ), as that may cause issues with search and filtering. Since you have spaces in the column names (also not recommended in SQL), you need to use accent graves, but please reconsider changing the column headers to be in one word.

    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

  •  4
    Sebastian Gendry replied

    Hey Aleksandar,

    Thank you for your feedback on spaces in my SQL column names. Will fix right away.

    Regarding my question, allow me to clarify what I am looking to achieve.

    Right now i can either show data in a page/post OR in the master-detail modal window.

    I was wondering if/how it is possible to have both options at the same time:

    A) I only have 1 details page and only need 1. (How) Can I include a link to this 1 page in the master detail window?

    B) Alternatively, I understand how to include this link to a page/post in the main wpDataTable, but if so (how) can I also have the master-detail modal display when users click on any given row?

  •  2,498
    Aleksandar replied

    Hi again Sebastian

    You can't have both - page and modal. It simply can't work with the built-in features of the plugin.

    A) If you enable the modal; and want to forward the link from a modal to the MD page, that won't work, because there's no data to be fetched from the modal, and output in the page. Meaning, you would see only the placeholders in the page.

    B) Same as A) - if the page is accessed directly, not through the table, it will only show placeholders, not the data pulled from the table.

    Please check out this idea of Master-Detail parent/child relation - it may help:

    First you will create that button column in your existing table with MD add-on and then set custom page where users will be redirected after click.

    Then on that custom page you will be insert table  created with SQL query and using placeholders.

    If you have that table in database then fine you ill use it for creating new table with SQL query and placeholders.

     IF you create manual table then you will use table that is created in database(you can find it on Editing tab on MySQL name table for editing). 

    Those table have names like wp_wpdatatable_1,wp_wpdatatable_2...

    You will use then those table to create new one with query. 

    So you will create new table like this

    SELECT * FROM table_name_from_mysql_name_option WHERE column_name = %VAR1%

    Then on that custom page will insert some default column_name value in shortcode like

    [wpdatatable id=1 var1=test]

    Now hooks. You will add this hook in your functions.php of your child theme or theme depends on what you are using to filter this var1

    and then you will use our hook for dynamic updating placeholders

    function updateVAR1($tableID){  global $wdtVar1;
          // check is set details data from POST, where you'll find all row data 
          // from MasterDetail after button click in first table
        if(isset($_POST['wdt_details_data'])){
            $detailsData= json_decode(stripslashes($_POST['wdt_details_data']), true);
        // instead of origin_header you will insert value from your column origin header
        // on Master-dettails docs you will find Instructions how to create custom
         // template (post or page) and below that is shown what is origin header
           $wdtVar1 = $detailsData['origin_header'];
        }
          }
    add_action('wpdatatables_before_get_table_metadata', 'updateVAR1');

    This is the only way because the shortcode is executed before the content on the page or post.

    Like this when user click on More details button(that you will create with MD) it will be redirect on your custom page(that you set in MD).

    On that page you will insert shortcode of Child table created from query and placeholder.

    After loading the page column value  will be replaced with placeholder, placeholders will be replaced in query and you will get table which is filtered with that placeholder.

    I hope that I am not confused you with this, but I try to be details as I can to understand what and how you can achieve with this.

    Let me know is this fit for your needs.


    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

  •  4
    Sebastian Gendry replied

    Hey Aleksandar,

    Thank you for your willingness to help me with this.

    From the top:

    #1: I know how to open data in the master-details modal or directly in a page. The plugin makes it very easy.

    #2: Are you saying that with this work-around I can have both the master-details modal display when a row is clicked AND the details page open when the button column is clicked (I'm already a bit confused there because if I create that column button in the master-detail plugin, then clicking on a row will link to the page, not the modal)?

    #3: I wanted to test what you describe anyway even though I don't fully understand how to use it and did the following:

    a) I created a new query (New wpDataTable #22) as follows:

    SELECT fun_wpdatatables.`var1`
    FROM fun_wpdatatables

    b) I created a page with the following code: [wpdatatable id=22 var1=GamePartialDesc]

    c) I added the following code to my functions.php child theme:

    function updateVAR1($tableID){  global $wdtVar1;
          // check is set details data from POST, where you'll find all row data 
          // from MasterDetail after button click in first table
        if(isset($_POST['wdt_details_data'])){
            $detailsData= json_decode(stripslashes($_POST['wdt_details_data']), true);
        // instead of origin_header you will insert value from your column origin header
        // on Master-dettails docs you will find Instructions how to create custom
         // template (post or page) and below that is shown what is origin header
           $wdtVar1 = $detailsData['GamePartialDesc'];
        }
          }
    add_action('wpdatatables_before_get_table_metadata', 'updateVAR1');

    d) and that's it. Is this correct? I didn't have much time to do full tests today and assume that with this option maybe I could achieve what I describe in #2 above. Let me know

    Thank you!


  •  2,498
    Aleksandar replied

    Hi again Sebastian.

    2. The approach would be this:

    In the first table, you enable Master-Detail, so it opens in a new page. On that page, you add the SQL query based table, which also has Master-Detail configured. So, with previously configured VAR placeholder, you would add that table on the Master-Detail page using a shortcode like [wpdatatable id=1 var1=customValue]. So, after that, in the hook you forward the parameter.

    This does require some knowledge of hooks and filters, and is not included in the provided support for the plugin.

    What you describe in #3 should work fine, but the query doesn't look correct. You should create a new table with:

    SELECT * FROM fun_wpdatatables
    WHERE some_column = '%VAR1%'

    So, the query displays fun_wpdatatables table where some_column = the placeholder. That placeholder needs to be defined in the Placeholders tab above the table, so the table has something to generate. Add any value that exists in the table, since you'll later change that dynamically.

    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