JqGrid export excel table code (php + jqgrid instance)

Source: Internet
Author: User
Tags jqgrid

Jqgrid export excel table code (php tutorial + jqgrid instance)
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 tutorial" 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 = ".../Webpage effects/jquery. webpage effects" type = "text/Webpage effects"> </script>
<Script src = "../js/i18n/grid. locale-en.js" type = "text/Webpage effects"> </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 code

<? 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;
?>

 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.