0
votes

Have run into a problem wiht jqGrid when I try to export a table to PDF, Excel or CSV.

Every time I run the code I get "Call to Undefined Method::jqGrid::exportToPdf" (or Excel or CSV, depending on which method I am using.

Here is a snip of the client side:

.jqGrid('navButtonAdd', '#ors_registrant_pager', {
id: 'exportToPdf',
caption: '',
title: 'Download PDF',
onClickButton: function(){
    grid.jqGrid('excelExport',{tag:"pdf","url":"info.php"});
}

Here is the server side php script in info.php:

$conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD);
$conn->query("SET NAMES utf8");

$grid = new jqGrid($conn);

$grid->SelectCommand = "SELECT lastName, firstName FROM user_table";
$grid->ExportCommand = "SELECT lastName FROM user_table";
$grid->dataType = "json";

$export = $_POST["oper"];

if($export == "pdf") {
    $grid->exportToPdf();
} else {
    $grid->queryGrid();
}

The grid loads correctly on the pageload, but as stated, when you click the PDF button on the bar I get that error. I've tried using all the parameters for the method to what is above with the same result. I've traced and the exportToPdf method does indeed exist in the jqGrid class.

I've searched and can't find any references to the problem. Any help would be much appreciated.

UPDATE

moved to Answer

1

1 Answers

0
votes

Ok, as it happens so many times, as soon as I posted I found the answer. The documentation is not correct in the Trirand site for PHP help. In the help it states to use the jqGrid class for PDF exports, but apparently you have to use the jqGridRender class instead.

To do the PDF export I had to change the $grid declaration as follows:

$grid = null;

$export = $_GET["oper"];

if($export == "pdf"){
    $grid = new jqGridRender($conn);
} else {
    $grid = new jqGrid($conn);
}

Doing so allows the grid to be exported.

I was going to delete the thread but I am leaving in case others run into the same problem in hopes this will help them out.