首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

YUI2.8 兑现datatable从server端动态获取数据,并实现分页功能(下)

2013-03-26 
YUI2.8 实现datatable从server端动态获取数据,并实现分页功能(下)7、编写JSP的程序,文件的路径:/yuiapp/Web

YUI2.8 实现datatable从server端动态获取数据,并实现分页功能(下)

7、编写JSP的程序,文件的路径:/yuiapp/WebRoot/pages/datatable/datatable01.jsp

文件的内容:

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
?String path = request.getContextPath();
?String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<%String sysPath =basePath+"appjs/yuijs/build"; %>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>datatable_01</title>
<style type="text/css">
/*margin and padding on body element
? can introduce errors in determining
? element position and are not recommended;
? we turn them off as a foundation for YUI
? CSS treatments. */
body {
?margin:0;
?padding:0;
}
</style>

<link rel="stylesheet" type="text/css" href="<%=sysPath %>/fonts/fonts-min.css" />
<link rel="stylesheet" type="text/css" href="<%=sysPath %>/paginator/assets/skins/sam/paginator.css" />
<link rel="stylesheet" type="text/css" href="<%=sysPath %>/datatable/assets/skins/sam/datatable.css" />
<link rel="stylesheet" type="text/css" href="<%=sysPath %>/container/assets/skins/sam/container.css" />
<script type="text/javascript" src="<%=sysPath %>/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript" src="<%=sysPath %>/connection/connection-min.js"></script>
<script type="text/javascript" src="<%=sysPath %>/json/json-min.js"></script>
<script type="text/javascript" src="<%=sysPath %>/element/element-min.js"></script>
<script type="text/javascript" src="<%=sysPath %>/paginator/paginator-min.js"></script>
<script type="text/javascript" src="<%=sysPath %>/datasource/datasource-min.js"></script>
<script type="text/javascript" src="<%=sysPath %>/datatable/datatable-min.js"></script>
<script type="text/javascript" src="<%=sysPath %>/dragdrop/dragdrop-min.js"></script>
<script type="text/javascript" src="<%=sysPath %>/container/container-min.js"></script>

<!--begin custom header content for this example-->
<style type="text/css">
/* custom styles for this example */
.yui-skin-sam .yui-dt-liner { white-space:nowrap; }
</style>

</head>
<body // Access to value in the server response
??????? }
??? };
???
??? // DataTable configuration
??? var myConfigs = {
??????? initialRequest: "pageSize=10&sort=id&dir=asc&startIndex=0",//"sort=ptInsId&dir=asc&startIndex=0", // Initial request for first page of data
??????? dynamicData: true, // Enables dynamic server-driven data
??????? sortedBy : {key:"id", dir:YAHOO.widget.DataTable.CLASS_ASC}, // Sets UI initial sort arrow
??????? paginator: new YAHOO.widget.Paginator(
??????????????? {?? rowsPerPage:10,
??????????????? ?firstPageLinkLabel : "首页",??
???????????????? lastPageLinkLabel : "末页",??
???????????????? previousPageLinkLabel:"上页",?
???????????????? nextPageLinkLabel:"下页"?
??????????? }) // Enables pagination
??? };
???
??? // DataTable instance
??? var myDataTable = new YAHOO.widget.DataTable("dynamicdata", myColumnDefs, myDataSource, myConfigs);
??? // Update totalRecords on the fly with value from server
??? myDataTable.handleDataReturnPayload = function(oRequest, oResponse, oPayload) {
??????? oPayload.totalRecords = oResponse.meta.totalRecords;
??????? return oPayload;
??? }???
??? return {
??????? ds: myDataSource,
??????? dt: myDataTable
??? };???????
}();
</script>

</body>
</html>

?

8、部署应用,启动tomcat,进行测试。

http://127.0.0.1:8080/yuiapp/pages/datatable/datatable01.jsp

?

点击上一页下一页的链接,则可以看到打印出对应的调试信息。

?getBookList is called....startIndex=0
?getBookList is called....startIndex=10
?getBookList is called....startIndex=0

?

当页面发送相同的请求时(包括参数相同),则不打印了,我觉得YUI会解析请求的

?

附件是我开发的程序,把YUI和jar给删除了。

?

我的个人联系方式是QQ 604320137 手机是1343917 2635 或?133 9175 8739,加我请注明是javaeye的yui。

?

热点排行