jQuery grid with PHP & MySQL
Important: This topic was written for older version v1.1.3 of the grid. Some examples may not work with the new version due to differences in the API. New version has easier way of integration with remote scripts, consult the demos for live examples of the new version. Anyway the basic concepts are still relevant and it makes a good read.
This tutorial serves to learn integration of jQuery grid with PHP using open standards based on RESTful API. We would go through every step but it's assumed that the user has basic working knowledge of PHP and MySQL and the user has already set up working environment vis-a-vis PHP/MySQL, so this post won't discuss the installation of PHP, MySQL, Apache/ IIS on Windows, Linux or any other OS.Get JSON data from PHP using associative arrays
In our first topic we would discuss the steps for getting JSON data from PHP for jQuery grid using associative arrays. This is how our client side file index.php looks like where include.php contains the jQuery and pqGrid include files.<?php require_once '../include.php'; ?> <script class="ppjs"> $(function () { var colM = [ { title: "Order ID", width: 100, dataIndx: "OrderID" }, { title: "Customer Name", width: 130, dataIndx: "CustomerName" }, { title: "Product Name", width: 190, dataIndx: "ProductName" }, { title: "Unit Price", width: 100, dataIndx: "UnitPrice", align: "right" }, { title: "Quantity", width: 100, dataIndx: "Quantity", align:"right" }, { title: "Order Date", width: 100, dataIndx: "OrderDate"}, { title: "Required Date", width: 100, dataIndx: "RequiredDate" }, { title: "Shipped Date", width: 100, dataIndx: "ShippedDate" }, { title: "ShipCountry", width: 100, dataIndx: "ShipCountry" }, { title: "Freight", width: 100, align: "right", dataIndx: "Freight" }, { title: "Shipping Name", width: 120, dataIndx: "ShipName" }, { title: "Shipping Address", width: 180, dataIndx: "ShipAddress" }, { title: "Shipping City", width: 100, dataIndx: "ShipCity" }, { title: "Shipping Region", width: 110, dataIndx: "ShipRegion" }, { title: "Shipping Postal Code", width: 130, dataIndx: "ShipPostalCode" } ]; var dataModel = { location: "remote", dataType: "JSON", method: "GET", getUrl : function () { return { url: 'remote.php'}; }, getData: function ( response ) { return { data: response }; } }; $("div#grid_php").pqGrid({ width: 900, height: 400, dataModel: dataModel, colModel: colM, bottomVisible: false, title: "Shipping Orders" }); }); </script>