Modern applications require real-time data updates. AG Grid can integrate with WebSockets to provide live data feeds without full refreshes. The key is using AG Grid's transaction API for surgical updates. For high-frequency updates (multiple messages per second), the UI stays completely stable. You can also use async transactions for efficient streaming updates. While these resources focus on Node.js backends, the same principles apply to PHP-based WebSocket servers using libraries like Ratchet. The AG Grid frontend connects to a WebSocket server and, upon receiving new data, calls applyServerSideTransaction to update only the changed rows.
// Define the grid options $options = [ 'columnDefs' => $columns, 'rowData' => [] ];
Adhering to these practices will protect your application from common web vulnerabilities.
In 2026, PHP is primarily used as an API layer to handle database operations securely. This updated example uses with prepared statements to prevent SQL injection. aggrid php example updated
: Enable immutableData: true and provide a getRowId function (using your database primary key) to optimize re-renders during updates.
– Using AG Grid’s Server-Side Row Model (recommended for large data) OR Infinite Row Model. Here we use the Server-Side Row Model for efficiency.
const columnDefs = [ field: "id", sortable: true, filter: true , field: "name", sortable: true, filter: true , field: "model", sortable: true, filter: true , field: "price", sortable: true, filter: "agNumberColumnFilter" ]; const gridOptions = columnDefs: columnDefs, pagination: true, paginationPageSize: 10 ; // Initialize the grid const gridDiv = document.querySelector('#myGrid'); const gridApi = agGrid.createGrid(gridDiv, gridOptions); // Fetch data from PHP backend fetch('data.php') .then(response => response.json()) .then(data => gridApi.setGridOption('rowData', data); ); Use code with caution. Copied to clipboard Key Update Notes Modern applications require real-time data updates
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC); $total = $pdo->query( "SELECT COUNT(*) FROM users" )->fetchColumn(); json_encode([ => (int)$total ]); Use code with caution. Copied to clipboard 3. Key Framework Integrations
is the updated method for instantiating grids in recent versions. 2. Backend: The PHP Script ( backend.php
In this example, we've created a simple AG Grid table using PHP and MySQL. We've demonstrated how to fetch data from a database and display it in an interactive table. AG Grid offers a wide range of features and customization options, making it a powerful tool for creating dynamic and interactive tables. The AG Grid frontend connects to a WebSocket
// Return AG Grid expected format echo json_encode([ 'success' => true, 'rows' => $rows, 'lastRow' => $totalRows ]); exit;
Are you using a (like Laravel or Symfony) or Vanilla PHP ?