Okay
  Public Ticket #2918656
Master /detail foreign key
Closed

Comments

  • Harold started the conversation

    I don't understand how to make a master/detail that performs a subquery.

    I have 2 views. View1 is master which is phone numbers and group count. I want to click row to pass phone# to View2 to get the details.

    I have view2 setup with FK in wp but don't see where/how to pass phone# to view2 to perform subquery.


    thanks

  •  472
    Isidora replied

    Hi Harold,

    Thank you for your purchase.

    Unfortunately this is not working like that. It is puling data from row of same table. So you will need to create query that will pull data from both views and then choose columns that you need for Master detail or  there is a workaraound with custom page or post, not for popup option.

    First, you need to set a custom page (post) where users will be redirected after clicking on the button or row.

    Then, on that custom page, you will insert a table created with an SQL query(View2) and using placeholders.

    So you will create a new table like this

    SELECT * FROM View2 WHERE column_name='%VAR1%'

    and provide some value in VAR1 input on Placehodlers tab to generate the table.

    Then on that custom page, you would insert some default column_name(you will replace it with phone or what ever is called in database)  and value(value from your phone column) in shortcode like

    [wpdatatable id=1 var1=test]

    Of course you will replace table id with id of your table.

    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 dynamically 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
         // origin_header of your phone column
           $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 the user clicks on the More details button or rowit will be redirected to your custom page (that you set in MD).

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

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

    Please note that if user directly access to that custom page it will see table that is filtered with default value that you set for var1 parameter in shortcode. If you do not want for user see data in this table, then provide value in var1 that is not exist in that phone column like testNoValue or somtning elese so when this will be replaced in query it will return empty table.

    I hope that I haven't confused you with this, but I try to be as detailed as I can so you can understand what and how you can achieve with this.

    Let me know if this fits your needs.

    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

  • Harold replied

    The master setting is set to call itself and it IS showing the details when I click on a row. Can I stop it from opening a new window?  It would be nice to keep the "clicked" row, is that possible or display next to details?

    Post page

    https://i.imgur.com/Sh3hCCZ.png



    Results:

    https://i.imgur.com/ta0k4Hi.png



    Thanks

  •  472
    Isidora replied

    Hi Harold,

    If I understand you right you have those tables on same page so when some one click on first table to open template in same window/tab?

    If that is try then you will need to make some changes.(This is planned so it will be implement in near future to choose opening template in same or new window/tab)

    You can change it in code in file wp-content/plugins/wdt-master-detail/class.masterdetail.wpdatacolumn.php around line 51 you will find this

    $formattedValue = "<form class="wdt_md_form" method="post" target="_blank" action="{$renderAction}"></form>

    and you have to change target="blank" to target="_self"

    $formattedValue = "<form class="wdt_md_form" method="post" target="_self" action="{$renderAction}"></form>

    also in same file on line 64 you will find this

    $formattedValue = "<form class='wdt_md_form' method='post' target='_blank' action='{$renderAction}'>

    and you have to replace with this

    $formattedValue = "<form class='wdt_md_form' method='post' target='_self' action='{$renderAction}'>

    Then, go to wp-content/plugins/wdt-master-detail/templates/md_modal.inc.php and change line 52 just like you did the others, so instead of:

    <form class="wdt_md_form" method="post" target="_blank" action="<?php echo $renderAction; ?>"></form>

    Change it to this:

    <form class="wdt_md_form" method="post" target="_self" action="<?php echo $renderAction; ?>"></form>

    That one's for row click.

    Please note that this will be affected for all tables where you are using Master detail option with custom page or post.

    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

  •  1
    Sue Hemmens replied

    Thanks both for making this public, very useful for me

  • Harold replied

    Thanks again.  Assume when plugin updates it will overwrite my changes. Would this make more since to add to a script to functions.php vs your method? I'm not a dev so not sure what I don't know.

  •  472
    Isidora replied

    Hi Harold,

    Yes it will be overwritten, but until next update I hope that this will be implemented as option so you will need to just turn it off or on. Unfortunately it is template so there is no hook that you can over this for row click function. For button click function it is available wpdatatables_filter_details_cell where you can change this. It is provide HTML element(as form for button action) and then then you need to search for this target element to replace it. Accept two parameters first is formatted value(string) - which contains that HTML and second one is table id(integer)

    function wpdatatables_filter_master_detail_cell( $formattedValue, $tableId)
    {
        //here you can set table id that you need
        // $tableId is int
        if ($tableId == 1) {
            $formattedValue = str_replace("target='_blank'","target='_self'", $formattedValue);
        }
        return $formattedValue;
    }
    add_filter('wpdatatables_filter_details_cell','wpdatatables_filter_master_detail_cell', 10, 2);

    Hi Sue,

    You are welcome.

    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