Do you need to implement or Server-Side Filtering to handle millions of rows?
Built-in filtering, sorting, grouping, pivoting, and editing.
use App\Models\User; use HeshamFouda\AgGrid\AgGridQueryBuilder; use HeshamFouda\AgGrid\Http\Requests\AgGridGetRowsRequest; aggrid php example updated
// --- SORTING --- // AG Grid sends sortModel: [colId: "salary", sort: "asc"] // We simulate sorting via GET params for this example: if (isset($_GET['sortCol']) && isset($_GET['sortDir'])) // Validate sortDir to prevent SQL injection $dir = strtoupper($_GET['sortDir']) === 'DESC' ? 'DESC' : 'ASC'; // Whitelist columns to prevent SQL injection $allowedCols = ['employee_name', 'salary', 'department']; if (in_array($_GET['sortCol'], $allowedCols)) $sql .= " ORDER BY " . $_GET['sortCol'] . " " . $dir;
?> Use code with caution. Copied to clipboard 4. Advanced: Server-Side Row Model For datasets with millions of rows, use the AG Grid Enterprise Server-Side Row Model Do you need to implement or Server-Side Filtering
<script> // Define Column Definitions const columnDefs = [ field: 'id', hide: true , // ID is hidden but needed for updates field: 'employee_name', filter: true, editable: true , field: 'job_title', editable: true , field: 'department', filter: true, editable: true ,
: Activating floatingFilter: true inside defaultColDef instantly gives users accessible, Excel-like inline row search bars. 'DESC' : 'ASC'; // Whitelist columns to prevent
| Old/Incorrect | Updated Solution | |---------------|------------------| | mysql_query() | PDO with prepared statements | | Returning all rows at once | Server-side row model | | Ignoring filterModel type | Handle contains , equals , greaterThan , etc. | | $_GET for parameters | Use php://input and JSON | | Hardcoded OFFSET without validating | Cast to (int) to prevent injection | | No lastRow calculation | Always return total filtered count |
If your dataset grows beyond 20,000 rows, Client-Side rendering will slow down the browser. You should upgrade the implementation to use AG Grid's :
This guide focuses on an updated implementation for , utilizing modern PHP best practices and AG Grid's latest Server-Side Row Model (SSRM) features. 1. The Strategy: Server-Side Row Model (SSRM)
<?php // Include the AG Grid library require_once 'ag-grid-community.js';