However, the are a few steps that you need to do in addition to that to make sure everything works as expected:
1. In the html or php file where the grid is constructed, the appropriate meta tag should be set.
... <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1251" /> ... </head> ...
2. The connection command to the database should be set in order characters to be displayed properly
For MySQL and PostgreSQL this is a
SET NAMES 'charset'This command should be executed before interacting with the grid.
For Microsoft SQL Server the connection info string should contain the charset setting as well:
<?php // Example connection $connectionInfo = array("UID" => 'user', "PWD" => 'password',"Database"=>"test", "CharacterSet" => "windows-1251", "ReturnDatesAsStrings" => true); $serverName = "localhost\SQLEXPRESS"; $conn = sqlsrv_connect( $serverName, $connectionInfo); ... // include the jqGrid Class require_once "php/jqGrid.php"; // include the SQL Server driver class require_once "php/jqGridSqlsrv.php"; ... ?>
3. And at end we should set $encoding variable in the grid. When this command is set the grid executes a PHP header function to send the appropriate header to the browser and more importantly - in case of 'json' output uses his own encode (when charset is <> utf-8). This is need because the built-in PHP functions for json encoding and decoding are utf-8 compatible only.
Again we ilustrate this with example. Let suppose that the database is encoded in windows-1251 charset. Using our example
Changes in the html file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1251" /> <title>PHP jqGrid Class Example</title> ...
The changes in the PHP script:
<?php require_once 'jq-config.php'; // include the jqGrid Class require_once "php/jqGrid.php"; // include the PDO driver class require_once "php/jqGridPdo.php"; // Connection to the server $conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD); // perform the set names command $conn->query("SET NAMES cp1251"); // Create the jqGrid instance $grid = new jqGrid($conn); // Set the encoding $grid->encoding = "windows-1251"; // Write the SQL Query $grid->SelectCommand = 'SELECT OrderID, OrderDate, CustomerID, Freight, ShipName FROM orders'; $grid->dataType = "json"; $grid->queryGrid(); ?>