Refresh DataTable without reloading page

Refresh DataTable without reloading page

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Refresh DataTable without reloading page

Updating a row's status in one tab often requires reflecting that change across other related views immediately. In your scenario, moving a record from the first table to Tab 2 triggers an AJAX call to dbo.php. Once the backend confirms the update, you need the second table to reflect this new state without triggering a full page reload or forcing the user to manually refresh. The challenge lies in synchronizing the client-side DataTable instance with the server response efficiently.

When you handle the success callback in jQuery's AJAX request, you are currently manipulating DOM elements directly using selectors like $('tr#'+id+''). This approach is fragile because DataTables often hides the original <tbody> content or renders rows dynamically based on a configuration object rather than static HTML IDs. Attempting to find a row by its ID inside a rendered DataTable frequently fails if that ID does not match the internal data structure or if the element was removed from the DOM during rendering.

To achieve the desired synchronization, you must interact with the DataTable API instead of raw jQuery selectors. The most reliable pattern is to pass the specific row index or data object to the row() method and then call cell().node() or cell(0).node() to access the underlying DOM element. Once you have the correct reference, you can update its visual properties or content.

Here is how you can refactor your success callback to target the second table specifically:

success : function(data){
    // Identify the row in Tab 2 that corresponds to this ID
    var $targetRow = $('#tab2_table').DataTable().row( { data: id } );
    
    if ( $targetRow.exists() ) {
        // Update the content of the specific cell or entire row
        $targetRow.cell(0).node().innerHTML = status; 
        
        // Apply visual changes to indicate the update
        $targetRow.row().node().classList.add('status-updated');
    } else {
        console.warn('Row with ID ' + id + ' not found in Tab 2.');
    }

    // Keep the original logic for Tab 1 if needed
    var $originalRow = $('#tab1_table').DataTable().row( { data: id } );
    if($originalRow.exists()){
        $originalRow.cell(0).node().classList.add('removed');
    }
}

This approach bypasses the need for hardcoded IDs on table rows, which is a common anti-pattern when using DataTables. By relying on the data property that matches your ID, you ensure that the API locates the correct row regardless of its current position in the DOM or any CSS classes applied by the library.

A critical trade-off to consider here is data consistency versus performance. If your second table relies on a separate AJAX call to fetch all records every time the first table changes, you risk creating a race condition where both tables display stale data briefly. The solution above minimizes network overhead by updating only the specific DOM nodes involved in the transaction.

If you are building this with Laravel, you might consider returning a JSON structure that explicitly maps IDs to updated values. While your current setup uses PHP files directly, wrapping these logic blocks into a single API endpoint (e.g., /api/update-status) ensures that all client-side scripts receive consistent data formats. This architectural shift aligns well with modern SPA patterns and reduces the complexity of managing multiple .php endpoints for different tabs.

Ensure that your DataTable initialization options on Tab 2 allow for direct manipulation via the API. If you have configured pageLength or specific rendering callbacks, verify that they do not interfere with the row lookup mechanism. Finally, always include a fallback check using .exists() to prevent JavaScript errors if the target row was never rendered or was filtered out of view.

Our network