Skip to content

General FAQs

General FAQs

Q) How to debug no records (blank grid)?

Few considerations before use

1) include the jqgrid_dist.php file before any thing rendered to output. 2) Check the ajax response of grid,

Also make sure you call '$g->render();' function before any HTML is rendered (echo'd) to output, as it expect exact JSON format for ajax calls. You can echo the output of render() function to desired location in html.

Use firefox->firebug->net->ajax-call of grid->response. You will see the output there, in case of any error. It should be proper JSON format data in order to render grid

Review this tutorial for 'debugging with firebug'.

To enable debugging errors,

1) Turn errors on. Goto jqgrid_dist.php make it 'on'

error_reporting(E_ALL); // show all messages
ini_set("display_errors","on"); // changed from off to on

2) If you are using non-mysql database,

$g = new jqgrid($db);
...
$g->con->debug = 1;

^ Top

Q) How can i integrate PHPGrid in MVC based frameworks like Laravel, Yii, Codeignitor, Zend Framework, CakePHP and others.

To integrate in MVC, You can divide code in 2 sections. And put first in controller and pass the $out variable to view, where you can render it with rest of JS/CSS files.

CONTROLLER PART

include("inc/jqgrid_dist.php");
$g = new jqgrid();
...
$out = $g->render("list1");

VIEW PART

<html>

<link rel="stylesheet" type="text/css" media="screen" href="js/themes/redmond/jquery-ui.custom.css"></link>
<link rel="stylesheet" type="text/css" media="screen" href="js/jqgrid/css/ui.jqgrid.css"></link>

<script src="js/jquery.min.js" type="text/javascript"></script>
<script src="js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>

<div style="margin:10px">
<?php echo $out?>
</div>

...

PHP Grid works independently from the framework lib and don't use data access layers of framework. In Codeigniter, the htaccess mod_rewrite param of QSA (query string append) is disabled. You might need to enable it in CI .htaccess file.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]

^ Top

Q) Grid only show Edit/Delete option only on first row / certain rows?

The first column of grid must have unique alphanumeric data (usually a PK). This is required for proper display as well as update & delete operations of particular row. Later, You can also hide that column by setting $col["hidden"] = true;

^ Top

Q) I'm getting JS error in browser console: 'jqGrid' is undefined OR Cannot read property 'bridge' of undefined?

It's usually due to order of including jQuery JS file OR possibly duplicate inclusion. Please see below.

Correct: Including jQuery before jqGrid JS file

<script src="../../lib/js/jquery.min.js" type="text/javascript"></script>
<script src="../../lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="../../lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="../../lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>

Incorrect: Not Including before jqGrid js file

<script src="../../lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="../../lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="../../lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
<script src="../../lib/js/jquery.min.js" type="text/javascript"></script>

Incorrect: Including jQuery twice, by theme template or other plugin

<script src="../../lib/js/jquery.min.js" type="text/javascript"></script>
<script src="../../lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="../../lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="../../lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>

<!-- some other code -->

<script src="<some-other-plugin>/js/jquery.min.js" type="text/javascript"></script>

Make sure you include JQuery JS file before other JS files and include only once in your page.

^ Top

Q) How to display grid with no primary key in table?

You can virtual column for unique data as first column of grid, and fill that column using filter_display event. It is required for various options e.g. displaying subgrid etc.

// virtual column to show grid

$col = array();
$col["title"] = "Id";
$col["name"] = "vid";
$col["width"] = "400";
$col["hidden"] = true;
$cols[] = $col;

$e["on_data_display"] = array("filter_display", null, true);
$g->set_events($e);

function filter_display($data)
{
    $i=1;
    foreach($data["params"] as &$d)
    {
        $d["vid"] = $i++;
    }
}

^ Top