page.html 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <!DOCTYPE html>
  2. <HTML>
  3. <HEAD>
  4. <TITLE> ZTREE DEMO - big data page</TITLE>
  5. <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  6. <link rel="stylesheet" href="../../../css/demo.css" type="text/css">
  7. <link rel="stylesheet" href="../../../css/zTreeStyle/zTreeStyle.css" type="text/css">
  8. <script type="text/javascript" src="../../../js/jquery-1.4.4.min.js"></script>
  9. <script type="text/javascript" src="../../../js/jquery.ztree.core-3.5.js"></script>
  10. <script type="text/javascript" src="../../../js/jquery.ztree.excheck-3.5.js"></script>
  11. <script type="text/javascript" src="../../../js/jquery.ztree.exedit-3.5.js"></script>
  12. <SCRIPT type="text/javascript">
  13. <!--
  14. var setting = {
  15. async: {
  16. enable: true,
  17. url: getUrl
  18. },
  19. check: {
  20. enable: true
  21. },
  22. data: {
  23. simpleData: {
  24. enable: true
  25. }
  26. },
  27. view: {
  28. addDiyDom: addDiyDom
  29. },
  30. callback: {
  31. beforeExpand: beforeExpand,
  32. onAsyncSuccess: onAsyncSuccess,
  33. onAsyncError: onAsyncError
  34. }
  35. };
  36. var zNodes =[
  37. {name:"page test", t:"Please click the paging buttons.", id:"1", count:2000, page:0, pageSize:100, isParent:true}
  38. ];
  39. var curPage = 0;
  40. function getUrl(treeId, treeNode) {
  41. var param = "id="+ treeNode.id +"_"+treeNode.page +"&count="+treeNode.pageSize,
  42. aObj = $("#" + treeNode.tId + "_a");
  43. aObj.attr("title", "Page " + treeNode.page + " / " + treeNode.maxPage + "")
  44. return "../asyncData/getNodesForBigData.php?" + param;
  45. }
  46. function goPage(treeNode, page) {
  47. treeNode.page = page;
  48. if (treeNode.page<1) treeNode.page = 1;
  49. if (treeNode.page>treeNode.maxPage) treeNode.page = treeNode.maxPage;
  50. if (curPage == treeNode.page) return;
  51. curPage = treeNode.page;
  52. var zTree = $.fn.zTree.getZTreeObj("treeDemo");
  53. zTree.reAsyncChildNodes(treeNode, "refresh");
  54. }
  55. function beforeExpand(treeId, treeNode) {
  56. if (treeNode.page == 0) treeNode.page = 1;
  57. return !treeNode.isAjaxing;
  58. }
  59. function onAsyncSuccess(event, treeId, treeNode, msg) {
  60. }
  61. function onAsyncError(event, treeId, treeNode, XMLHttpRequest, textStatus, errorThrown) {
  62. var zTree = $.fn.zTree.getZTreeObj("treeDemo");
  63. alert("ajax error...");
  64. treeNode.icon = "";
  65. zTree.updateNode(treeNode);
  66. }
  67. function addDiyDom(treeId, treeNode) {
  68. if (treeNode.level>0) return;
  69. var aObj = $("#" + treeNode.tId + "_a");
  70. if ($("#addBtn_"+treeNode.id).length>0) return;
  71. var addStr = "<span class='button lastPage' id='lastBtn_" + treeNode.id
  72. + "' title='last page' onfocus='this.blur();'></span><span class='button nextPage' id='nextBtn_" + treeNode.id
  73. + "' title='next page' onfocus='this.blur();'></span><span class='button prevPage' id='prevBtn_" + treeNode.id
  74. + "' title='prev page' onfocus='this.blur();'></span><span class='button firstPage' id='firstBtn_" + treeNode.id
  75. + "' title='first page' onfocus='this.blur();'></span>";
  76. aObj.after(addStr);
  77. var first = $("#firstBtn_"+treeNode.id);
  78. var prev = $("#prevBtn_"+treeNode.id);
  79. var next = $("#nextBtn_"+treeNode.id);
  80. var last = $("#lastBtn_"+treeNode.id);
  81. treeNode.maxPage = Math.round(treeNode.count/treeNode.pageSize - .5) + (treeNode.count%treeNode.pageSize == 0 ? 0:1);
  82. first.bind("click", function(){
  83. if (!treeNode.isAjaxing) {
  84. goPage(treeNode, 1);
  85. }
  86. });
  87. last.bind("click", function(){
  88. if (!treeNode.isAjaxing) {
  89. goPage(treeNode, treeNode.maxPage);
  90. }
  91. });
  92. prev.bind("click", function(){
  93. if (!treeNode.isAjaxing) {
  94. goPage(treeNode, treeNode.page-1);
  95. }
  96. });
  97. next.bind("click", function(){
  98. if (!treeNode.isAjaxing) {
  99. goPage(treeNode, treeNode.page+1);
  100. }
  101. });
  102. };
  103. $(document).ready(function(){
  104. $.fn.zTree.init($("#treeDemo"), setting, zNodes);
  105. });
  106. //-->
  107. </SCRIPT>
  108. <style type="text/css">
  109. .ztree li span.button.firstPage {float:right; margin-left:2px; margin-right: 0; background-position:-144px -16px; vertical-align:top; *vertical-align:middle}
  110. .ztree li span.button.prevPage {float:right; margin-left:2px; margin-right: 0; background-position:-144px -48px; vertical-align:top; *vertical-align:middle}
  111. .ztree li span.button.nextPage {float:right; margin-left:2px; margin-right: 0; background-position:-144px -64px; vertical-align:top; *vertical-align:middle}
  112. .ztree li span.button.lastPage {float:right; margin-left:2px; margin-right: 0; background-position:-144px -32px; vertical-align:top; *vertical-align:middle}
  113. </style>
  114. </HEAD>
  115. <BODY>
  116. <h1>Loading Data By Pagination</h1>
  117. <h6>[ File Path: bigdata/page.html ]</h6>
  118. <div class="content_wrap">
  119. <div class="zTreeDemoBackground left">
  120. <ul id="treeDemo" class="ztree"></ul>
  121. </div>
  122. <div class="right">
  123. <ul class="info">
  124. <li class="title"><h2>1, Explanation of large data load</h2>
  125. <ul class="list">
  126. <li>1) Pagination can be an effective solution to the large number of child nodes of the situation.</li>
  127. <li>2) Using custom method to display the pagination button.</li>
  128. <li class="highlight_red">3) Pagination lead to the association of checkbox can not be achieved, only correction after show each page . Because of the time limitation, Demo does not deal with association of checkbox.</li>
  129. <li class="highlight_red">4) The use of pagination, you can only get the current page node data from zTree. You can save the data after each page loading as the cache, according to the demand to determine the specific methods.</li>
  130. </li>
  131. <li class="title"><h2>2, Explanation of setting</h2>
  132. <ul class="list">
  133. <li>Need to set the parameters in setting.async</li>
  134. <li>No other special configuration, the user can set their own requirements.</li>
  135. </ul>
  136. </li>
  137. <li class="title"><h2>3, Explanation of treeNode</h2>
  138. <ul class="list">
  139. <li>No special requirements on the node data, the user can add custom attributes.</li>
  140. </ul>
  141. </li>
  142. </ul>
  143. </div>
  144. </div>
  145. </BODY>
  146. </HTML>