Okay
  Public Ticket #3551173
Ajax and reload table
Closed

Comments

  • Jeff Margel started the conversation

    What I am trying to do is, I have a page with a wpdatatable that lists a client's orders (just the order header).  When a user clicks on a record(row) and then a button, it should open up a popup (from popup maker plugin) with another wpdatable that lists the line items.

    The only way this works is when I use javascript and then push it to PHP which then adds a shortcode, however it only shows the table in HTML format.  So, this solution does not work for me.

    Thought of another idea to push it to PHP and use the wp_update_post function.  This actually puts the shortcode into the post, and shows the echo command with the correct post_data, however the wpdatatable is not showing the correct record.  It's only when I refresh the browser that it will then display it.

    I believe it's a caching issue, I have my cache plugin turned off and in my code i have it set to not only just 'no cache' but also do a ajax.reload on the wpdatatable, but it's still not working.  Here is my code, hoping someone can help me out.  Does WPDatatable cache itself?

    Javascript code: 

    <script>
    function openLI() {
         
    var $selectedRow = jQuery('.wpDataTable tr.selected');
     if ($selectedRow.length === 0) {
        alert('Please select a row.');
      }
    else {

    var rowData = wpDataTables['table_4'].fnGetData($selectedRow[0]);
    var value = rowData[1];
    var ord_no = value.trim();
    var myVar = ord_no;

        // AJAX request to update the post
     PUM.clearCookies(2986);
    jQuery.ajaxSetup({ cache: false });
        jQuery.ajax({
            type: 'POST',
     url: '/update-post.php?' + new Date().getTime(),
            data: {
               post_id: 2986,
               post_content: myVar,
            },
    cache: false,
            success: function(data) {
     console.log("The ajax request succeeded!");
     console.log("Data: " + data);
     setTimeout(function () {
            jQuery('#table_4').DataTable().ajax.reload();
        }, 1000); // Adjust the delay as needed

               PUM.open(2986);

     setTimeout(function () {
            jQuery('#table_4').DataTable().ajax.reload();
        }, 1000); // Adjust the delay as needed

            }
        });
    }
    }

    </script>

    PHP Code: 

    <?php


    ini_set('display_errors', 1);
    require_once('wp-load.php');
        $post_id = isset($_POST['post_id']) ? intval($_POST['post_id']) : 0;

     $post_content = $_POST['post_content'];echo json_encode($post_content);

    echo 'Post ID: ' . json_encode($post_id);
    echo 'Post Content: ' . json_encode($post_content);

    //  $post_content = sanitize_text_field($_POST['post_content'])

        $post = get_post($post_id);
     $post_data = array(
            'post_id' => $post_id,
    'post_content' => '[wpdatatable id=4 var1=' . $post_content .']',
        );

    $updated_post_id = wp_update_post($post_data);

        if (is_wp_error($updated_post_id)) {
            // Handle error
            echo json_encode(array('success' => false, 'message' => $updated_post_id->get_error_message()));

        } else {
            // Post updated successfully
            echo json_encode(array('success' => true, 'message' => 'Post updated successfully! ', $post_data));

        }

    ?>

  •  1,698
    Miloš replied



    Hello,

    This is a high level of custom solution, so i am sorry, but our Support is not able to cover any custom work/solutions.


    At this time, we don't have any built-in solution to achieve this

    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)


    2. That being said, if you manage to somehow pull it off, but if our Admin-Ajax call of the Table is prevented from loading - it can be if you have Caching on the Page and if you use a server-side processing Table.


    We currently have this issue which only happens for server-side processing tables when you have caching active on the page.

    For the Manual Tables, it is not possible to disable server-side processing,

    but you can make a new SQL Query based table from the same data which is stored in a Manual Table,

    by checking the MySQL Table name inside the Editing settings,

    then make an SQL Query like :  SELECT * FROM TableName.  ( of course, you can change the Query if you just wish to pull specific columns only)

    For any SQL Query based Table which has less than 2 thousand rows, you will be able to toggle server-side processing in the Data Source settings.

    Our developers are intensively working to resolve this issue, as soon as possible. I can't say an ETA on it, unfortunately.

    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.

    -

    For the time being, the only solution will be either to disable caching only for pages where you have the tables, or perhaps disable caching entirely, if possible.

    Most caching Plugins have the option to add URL's that will be excluded, so if possible, see if you can add the Pages with tables there, and that should solve it for now.

    Or you can try disabling server-side processing in your Table.


    I hope that helps.


    Kind Regards, 

    Miloš Jovanović
    [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

  • Jeff Margel replied

    I tried it with caching disabled, completely and still getting the issue.  If I manually go into the popup maker post and change the shortcode and hit save and it still shows the wrong ord_no.

  •  1,698
    Miloš replied

    Hi Jeff,

    I am sorry to see that it is still not working, but this is a very high level of custom solution, so our Support will not be able to troubleshoot it.

    As you described, and if we understood the main points of the use-case/ what you tried to do;

    you are basically not simply posting our Table's shortcode on a WP Page, but rather you are trying to 'trigger' a list of items which are stored in one of our Tables, but trying to push it through a Plugin with which we don't have any kind of integration with ( a popup (from popup maker plugin)),

    with Custom JavaScript and Custom PHP code.

    -

    Our Support can try to advise you for some use-cases where we already had users report success, or some specific custom examples shared by our developers;

    but for something like this, we do not have anything working to share yet.


    We don't have any built-in solution to achieve this, either.

    If you wish to see a built-in solution for something like that, 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

    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