JQGrid PHP导出网格和子网格到pdf

时间:2015-05-07 04:48:12

标签: php pdf jqgrid export subgrid

我是JQgrid PHP的新手。我可以将表数据导出为pdf格式。我的桌子有一个子网格。有没有办法将表格与子网格一起导出到PDF?

1 个答案:

答案 0 :(得分:-1)

出口你可以尝试这个 这是显示jqgrid表的HTML PAGE:

  <?php 
require_once '../../../jq-config.php'; 
// include the jqGrid Class 
require_once ABSPATH."php/jqGrid.php"; 
// include the driver class 
require_once ABSPATH."php/jqGridPdo.php"; 
// LOAD lang file 
require_once(ABSPATH.'/php/tcpdf/config/lang/eng.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'; 
// Let the grid create the model 
$grid->setColModel(); 
// 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", 
    "caption"=>"PDF export" 
)); 
// Change some property of the field(s) 
$grid->setColProperty("OrderDate", array( 
    "formatter"=>"date", 
    "formatoptions"=>array("srcformat"=>"Y-m-d H:i:s","newformat"=>"m/d/Y"), 
    "search"=>false 
    ) 
); 
$grid->setColProperty("ShipName", array("width"=>"250")); 
$grid->setColProperty("Freight", array("label"=>"Test", "align"=>"right")); 
if($grid->oper == "pdf") { 
    $grid->setPdfOptions(array( 
        // reprint table header  
        "shrink_cell"=>false, 
        "reprint_grid_header" => true 
        )); 
} 

// Enable navigator 
$grid->navigator = true; 
// Enable excel export 
$grid->setNavOptions('navigator', array("pdf"=>true,"add"=>false,"edit"=>false,"del"=>false,"view"=>false, "excel"=>false)); 
// Enjoy 

$grid->renderGrid('#grid','#pager',true, null, null, true,true); 
?> 

或者您可以使用fpdf更轻松

enter link description here

您可以尝试查看文档以获取更多jqgrid

示例