Skip to content

Aggrid Php Example Updated May 2026

This script acts as your API. It connects to a database and returns data in JSON format, which AG Grid expects. query( "SELECT id, name, email, role FROM users" ); $data = $stmt->fetchAll(PDO::FETCH_ASSOC); json_encode($data); (PDOException $e) json_encode([ => $e->getMessage()]);

Elara smiled. She loved AG Grid – its infinite scrolling, its cell editing, its ability to handle a million rows without breaking a sweat. But marrying it with a traditional PHP backend? That was the delicate dance. aggrid php example updated

<script> const columnDefs = [ field: "id", sortable: true, filter: "agNumberColumnFilter", width: 90 , field: "name", sortable: true, filter: "agTextColumnFilter", editable: true , field: "category", sortable: true, filter: "agTextColumnFilter", editable: true , field: "price", sortable: true, filter: "agNumberColumnFilter", editable: true, cellRenderer: "agAnimateShowChangeCellRenderer" , field: "stock", sortable: true, filter: "agNumberColumnFilter", editable: true , This script acts as your API

She wrote a modern server.php using Slim Framework 4 (instead of raw mysqli), with prepared statements, PDO, and server-side row model support: She added a new route: | Action |

// Handle PUT to update a row if ($request_method === 'PUT' && isset($_GET['action']) && $_GET['action'] === 'updateRow') $stmt = $pdo->prepare("UPDATE products SET name=:name, category=:category, price=:price, stock=:stock WHERE id=:id"); $stmt->execute([ ':id' => $input['id'], ':name' => $input['name'], ':category' => $input['category'], ':price' => $input['price'], ':stock' => $input['stock'] ]); echo json_encode(['success' => true]); exit;

She added a new route:

| Action | AG Grid Request parameter | PHP handling | |--------|--------------------------|---------------| | Sort | sortModel: [colId:"price", sort:"desc"] | Builds ORDER BY price DESC | | Text filter | filterModel: product_name: filter: "laptop", type: "contains" | product_name LIKE '%laptop%' | | Number filter | filterModel: price: filter: 100, type: "greaterThan" | price > 100 | | Date filter | filterModel: last_updated: dateFrom: "2024-01-01" | DATE(last_updated) >= '2024-01-01' | | Pagination | startRow: 200, endRow: 300 | LIMIT 100 OFFSET 200 |