This updated AG Grid PHP example gives you a robust, secure, and scalable foundation for integrating AG Grid with a modern PHP backend. You can now handle millions of rows with real-time filtering, sorting, and pagination—without bogging down the client’s browser.
Key takeaways:
Next steps:
References:
Need help? Copy the code above, adjust your database credentials, and you’ll have an enterprise-grade datagrid running in under 30 minutes. This is the most current and detailed AG Grid PHP example available online as of 2025. aggrid php example updated
Last updated: January 2025 – Compatible with AG Grid v31.3+, PHP 8.2/8.3, and MySQL 8.0.
This guide bridges the gap between the frontend JavaScript grid and the backend PHP server, covering the two most common scenarios: Server-Side Sorting/Filtering and Inline Editing.
To keep the grid updated after any PHP-side change (e.g., another user updates data), implement polling or WebSockets. A simple approach:
setInterval(() =>
gridOptions.api.refreshServerSideStore( purge: true );
, 30000); // refresh every 30 seconds
Or use AG Grid Transaction Updates for optimistic UI: This updated AG Grid PHP example gives you
// After successful update via PHP
gridOptions.api.applyServerSideTransaction(
update: [updatedRowData]
);
Create a table products to demonstrate dynamic data updates.
CREATE DATABASE aggrid_demo; USE aggrid_demo;CREATE TABLE products ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255) NOT NULL, category VARCHAR(100), price DECIMAL(10,2), stock INT DEFAULT 0, last_updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP );
INSERT INTO products (name, category, price, stock) VALUES ('Laptop Pro', 'Electronics', 1299.99, 25), ('Wireless Mouse', 'Accessories', 29.99, 150), ('Mechanical Keyboard', 'Accessories', 89.50, 75), ('USB-C Hub', 'Cables', 45.00, 40), ('Monitor 27"', 'Electronics', 299.99, 12);
| Feature | Description | |---------|-------------| | Server-side pagination | Load data in chunks (e.g., 100 rows at a time) | | Sorting | Multi-column sorting via PHP | | Filtering | Text, numeric, date range filters | | Row selection | Checkbox + server-side sync | | CRUD operations | Add, edit, delete rows via PHP endpoints | | Excel export | Export filtered/current grid data |
Let’s create a sample products table with 1 million rows for scalability testing.
CREATE TABLE `products` (
`id` int NOT NULL AUTO_INCREMENT,
`product_name` varchar(255) NOT NULL,
`category` varchar(100) NOT NULL,
`price` decimal(12,2) NOT NULL,
`stock_quantity` int NOT NULL,
`last_updated` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `idx_category` (`category`),
KEY `idx_price` (`price`)
);
Insert test data (adjust for your needs):
INSERT INTO products (product_name, category, price, stock_quantity)
SELECT
CONCAT('Product ', SEQ),
ELT(1 + FLOOR(RAND() * 5), 'Electronics', 'Clothing', 'Books', 'Toys', 'Furniture'),
ROUND(RAND() * 500, 2),
FLOOR(RAND() * 1000)
FROM
(SELECT @ROW := @ROW + 1 AS SEQ FROM information_schema.columns, (SELECT @ROW := 0) r LIMIT 100000) t;
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
email VARCHAR(100) NOT NULL UNIQUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);