PHP的页面,表格嵌入分页条,小结:
参考:http://www.jeasyui.com/tutorial/datagrid/datagrid2.php
注意:
To load data from remote server, you should set 'url' peoperty, where server will return JSON format data. see datagrid document for more about the data format.
We defines datagrid columns and set 'pagination' property to true, which will generate a pagination bar on datagrid bottom. The pagination will send two parameters to server:
- page: The page number, start with 1.
- rows: The page rows per page.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="keywords" content="jquery,ui,easy,easyui,web">
<meta name="description" content="easyui help you build your web page easily!">
<title>jQuery EasyUI Demo</title>
<link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/easyui/themes/icon.css">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="http://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>
</head>
<body>
<h1>DataGrid</h1>
<table id="tt" class="easyui-datagrid" style="width:600px;height:250px"
url="datagrid2_getdata.php"
title="Load Data" iconCls="icon-save"
rownumbers="true" pagination="true">
<thead>
<tr>
<th field="itemid" width="80">Item ID</th>
<th field="productid" width="80">Product ID</th>
<th field="listprice" width="80" align="right">List Price</th>
<th field="unitcost" width="80" align="right">Unit Cost</th>
<th field="attr1" width="150">Attribute</th>
<th field="status" width="60" align="center">Stauts</th>
</tr>
</thead>
</table>
</body>
</html>
<?php
$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
$offset = ($page-1)*$rows;
$result = array();
$conn = mysql_connect('127.0.0.1','root','root');
mysql_select_db('mydb',$conn);
$rs = mysql_query("select count(*) from item");
$row = mysql_fetch_row($rs);
$result["total"] = $row[0];
$rs = mysql_query("select * from item limit $offset,$rows");
$rows = array();
while($row = mysql_fetch_object($rs)){
array_push($rows, $row);
}
$result["rows"] = $rows;
echo json_encode($result);
?>