Okay
  Public Ticket #3678327
shortcode
Closed

Comments

  • Mark started the conversation

    Is there a way of changing a shortcode var1 value after a page has been redender?

    [wpdatatable id=66 var1="'C0-0000"]

    Some user action, where a new value for var1 is selected

    [wpdatatable id=66 var1="'C6-0308"]



  • Mark replied

    Here is a code snippet I have tried.... it fails


    !-- Container for the wpDataTable shortcode -->
    <div id="wpdatatable-container">
        [wpdatatable id=66 var1="C00-0000"]
    </div>

    <!-- User interaction element (button) -->
    <button id="change-var1">Change var1</button>

    <script>
    document.getElementById('change-var1').addEventListener('click',function() {
        // New value for var1
        const newVar1Value = "C00-1234";
       
        // Update the container with the new shortcode
        document.getElementById('wpdatatable-container').innerHTML = `[wpdatatable id=66 var1="${newVar1Value}"]`;
        
        // Reinitialize wpDataTables (assuming you have a function to do this)
        // Note: This step depends on how wpDataTables is set up and initialized in your WordPress site.
        // You might need to trigger an AJAX call or a function to reload the table data.
    //    wpDataTables.fnDraw();
    });

    </script>


  •  1,846
    Miloš replied

    Hi Mark,

    Sorry to disappoint you, but at this time, we don't have any built-in solution to achieve changing of the VAR in the Table's shortcode, after it has rendered on a Page, based on a user's action after it loaded.

    You can suggest it to our developers, though - they will do their best to make a solution in the future.

    Please feel free to search on our suggestions page

     to see if someone may be already suggested this feature. If you can't see it, feel free to add your suggestion there,  and as more people vote, the feature will move higher on the priority list.

    You can certainly follow our changeLog page if you'd like ( it is also available in the plugin dashboard), where we state any changes/new features/bug fixes during updates;

    and our newsletter, so you're informed about new features, bug fixes, freebies, etc.

    -

    If you have coding skills and wish to try to make a custom solution now, you can check out our available hooks for Developers on this documentation and see if you can find any hook that might help.

    Please be advised that custom solutions with hooks are not included in our support.

    You can also research resources such as Stack Overflow to see if any other user perhaps found a workaround.

    ( We do like to give examples for certain solutions, but for this use-case, we, unfortunately, don't have anything yet)


    Kind Regards, 

    Miloš Jovanović
    [email protected]

    Rate my support

    Try our FREE mapping plugin! MapSVG - easy Google maps, interactive SVG maps and floor plans, choropleth maps and much more - https://wordpress.org/plugins/mapsvg-lite-interactive-vector-maps/

    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 replied

    I found a way to change a shortcode parm using input from a user.   Can you  post the solution to your website

    Add the following to function.php

    function modify_wpdatatable_var1($atts) {
        if (isset($_POST['submit_var1']) && !empty($_POST['var1'])) {
            $var1_value = sanitize_text_field($_POST['var1']);
            $atts['var1'] = $var1_value;
        }
        return $atts;
    }
    add_filter('shortcode_atts_wpdatatable', 'modify_wpdatatable_var1', 10, 1);

    function display_wpdatatable_with_user_input() {
        ?>
        <form method="post" action="">
            <label for="var1">Enter Var1 Value:</label>
            <input type="text" id="var1" name="var1" value="">
            <input type="submit" name="submit_var1" value="Submit">
        </form>
        <?php
        if (isset($_POST['submit_var1']) && !empty($_POST['var1'])) {
            $var1_value = sanitize_text_field($_POST['var1']);
            echo do_shortcode('[wpdatatable id=66 var1="' . esc_attr($var1_value) . '"]');
        } else {
            echo '<p>Please enter a value for var1.</p>';
        }
    }
    add_shortcode('wpdatatable_user_input', 'display_wpdatatable_with_user_input');

    ____________________________________-

    Add the shortcode [wpdatatable_user_input] to the post or page where you want the form and table to appear:



  •  1,846
    Miloš replied

    Hi Mark,

    That is awesome, thank you so much for sharing this solution with us.

    I will pass it to our developers and we will discuss it with our management what might be the best way to post this somewhere, either on our Site or Documentation and/or perhaps in the FAQ section.

    We will also note it for our developers, it will certainly help with the Plugin's future development for native features.


    Thanks again.

    Kind Regards, 

    Miloš Jovanović
    [email protected]

    Rate my support

    Try our FREE mapping plugin! MapSVG - easy Google maps, interactive SVG maps and floor plans, choropleth maps and much more - https://wordpress.org/plugins/mapsvg-lite-interactive-vector-maps/

    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