jqgrid 導出excel表格代碼(php教程+jqgrid實例)
require_once '../../../tabs.php';
?>
<!doctype html public "-//w3c//dtd xhtml 1.0 strict//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd">
<html>
<head>
<title>jqgrid php demo</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css教程" media="screen" href="../../../themes/redmond/jquery-ui-1.7.1.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="../../../themes/ui.jqgrid.css" />
<link rel="stylesheet" type="text/css" media="screen" href="../../../themes/ui.multiselect.css" />
<style type="text">
html, body {
margin: 0; /* remove body margin/padding */
padding: 0;
overflow: hidden; /* remove scroll bars on browser window */
font-size: 75%;
}
</style>
<script src="../../../網頁特效/jquery.網頁特效" type="text/網頁特效"></script>
<script src="../../../js/i18n/grid.locale-en.js" type="text/網頁特效"></script>
<script type="text/javascript">
$.jgrid.no_legacy_api = true;
$.jgrid.usejson = true;
</script>
<script src="../../../js/jquery.jqgrid.min.js" type="text/javascript"></script>
<script src="../../../js/jquery-ui-1.7.2.custom.min.js" type="text/javascript"></script>
</head>
<body>
<div>
<?php include ("grid.php");?>
</div>
<br/>
<?php tabs(array("grid.php"));?>
</body>
</html>php代碼
<?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";
// 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, freight, shipname from longorders';
// set the ouput 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');
$grid->optimizesearch = true;
// set some grid options
$grid->setgridoptions(array("rownum"=>100,"sortname"=>"orderid","height"=>150));
// 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
)
);
// enable toolbar searching
$grid->toolbarfilter = true;
$grid->setfilteroptions(array("stringresult"=>true));
// enjoy
$grid->rendergrid('#grid','#pager',true, null, null, true,true);
$conn = null;
?>