The setColModel method uses the names of the database columns (fields) as default column header labels. In some cases when the number of columns is relatively big, you can use the third parameter in the method to add custom column headers instead of calling setColProperty with the label attribute.

The array used as a parameter should be an associative array - the key should correspond to the name of the database column (field) in the query and the value should be the desired column header corresponding to that column. It is not neccessary that the length of the array corresponds to the length of colModel.

Let suppose that in our example we want to change "OrderID" to "Id" and "OrderDate" to "Date".

<?php require_once 'jq-config.php'; // include the jqGrid Class require_once "php/jqGrid.php"; // include the driver class require_once "php/jqGridPdo.php"; // Connection to the server $conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD); // Tell the db that we use utf-8 $conn->query("SET NAMES utf8"); // Create the jqGrid instance $grid = new jqGridRender($conn); // Write the SQL Query $grid->SelectCommand = 'SELECT OrderID, OrderDate, CustomerID, ShipName, Freight FROM orders'; // Set output format to json $grid->dataType = 'json'; // Definition of the labels $mylabels = array("OrderID"=>"Id", "OrderDate"=>"Date"); // Let the grid create the model with the desired labels $grid->setColModel(null, null, $mylabels); // Set the url from where we obtain the data $grid->setUrl('grid.php'); // Set some grid options $grid->setGridOptions(array( "rowNum"=>10, "rowList"=>array(10,20,30), "sortname"=>"OrderID" )); $grid->renderGrid('#grid','#pager',true, null, null, true,true); $conn = null; ?>