dojo中 的 grid 的改进:增加分页导航条

前端之家收集整理的这篇文章主要介绍了dojo中 的 grid 的改进:增加分页导航条前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
    @H_502_1@ dojo.provide("navigationGrid");
  1. dojo.require("dojox.grid.DataGrid");
  2. dojo.require('dijit.Toolbar');
  3. dojo.require("dijit.form.Button");
  4. dojo.require("dijit.ToolbarSeparator");
  5. dojo.declare("navigationGrid",dojox.grid.DataGrid,{
  6. //当前页码
  7. currentPage:1,
  8. totalPage:1,
  9. maxPageNum:5,0); background-color:inherit">//页码按钮
  10. _pageBtns:null,
  11. //导航条对象
  12. _naviBar: _firstBtn: _prvIoUsBtn: _nextBtn: _lastBtn: _pageLoaded:false,108); list-style:decimal-leading-zero outside; color:inherit; line-height:24px; margin:0px!important; padding:0px 3px 0px 10px!important">
  13. postCreate:function(){
  14. this.inherited(arguments);
  15. this._pageBtns=[];
  16. this._naviBar=newdijit.Toolbar(
  17. {
  18. style:"width:100%;text-align:right"
  19. });
  20. this._firstBtn=newdijit.form.Button({
  21. label:"首页"
  22. ,disabled:true
  23. ,iconClass:"navi-first",108); list-style:decimal-leading-zero outside; color:inherit; line-height:24px; margin:0px!important; padding:0px 3px 0px 10px!important"> onClick:dojo.hitch(this,"_locate",'first')
  24. this._prvIoUsBtn= label:"上一页"
  25. "navi-prevIoUs",'pre')
  26. this._nextBtn= label:"下一页"
  27. "rtl"
  28. "navi-next",248)"> onClick:dojo.hitch('next')
  29. });
  30. this._lastBtn=newdijit.form.Button({
  31. label:"末页"
  32. true
  33. "rtl"
  34. "navi-last",'last')
  35. this._naviBar.addChild(this._firstBtn);
  36. newdijit.ToolbarSeparator());
  37. this._prvIoUsBtn);
  38. this._nextBtn);
  39. this._lastBtn);
  40. this._naviBar.placeAt(this.domNode,"after");
  41. //this._naviBar.startup();
  42. },248)"> _locate:function(s){
  43. switch(s){
  44. case'first':
  45. this._navigate(1);
  46. break;
  47. case'pre':
  48. this._navigate(this.currentPage-1);
  49. break;
  50. case'next':
  51. this.currentPage+1);
  52. case'last':
  53. this.totalPage);
  54. default:
  55. }
  56. },248)"> _updateBtnStatus:function(pageNo){
  57. /*
  58. *更新按钮的状态和样式
  59. */
  60. if(pageNo>1){
  61. this._firstBtn.set('disabled',false);
  62. this._prvIoUsBtn.set('disabled',153); font-weight:bold; background-color:inherit">false);
  63. }else{
  64. true);
  65. true);
  66. if(pageNo<this.totalPage){
  67. this._nextBtn.set('disabled',153); font-weight:bold; background-color:inherit">this._lastBtn.set('disabled',248)"> }else{
  68. }
  69. //清除当前页的样式
  70. /*varcurrentPageIdx=(this.maxPageNum?this.currentPage%this.maxPageNum:this.maxPageNum)-1;
  71. varpageNoIdx=(this.maxPageNum?pageNo%this.maxPageNum:this.maxPageNum)-1;
  72. pageNoIdx=pageNoIdx<0?this.maxPageNum-1:pageNoIdx;
  73. if(this._pageBtns[currentPageIdx]){
  74. this._pageBtns[currentPageIdx].set('class','');
  75. }
  76. if(this._pageBtns[pageNoIdx]){
  77. this._pageBtns[pageNoIdx].set('class','navi-currentPage');
  78. }*/
  79. /**
  80. *重新载入当前页面
  81. */
  82. reload:function(){
  83. varrow=this._pageToRow(this._fetch(row,0); background-color:inherit">*指向导航页面
  84. _navigate:if(this.currentPage==pageNo){return}
  85. if(pageNo<1||pageNo>this.totalPage){return}
  86. this._updateBtnStatus(pageNo);
  87. this._pageToRow(pageNo-1);
  88. this.currentPage=pageNo;
  89. //this._clearData();
  90. _onFetchComplete:function(items,req){
  91. if(!this.scroller){return;}
  92. if(items&&items.length>0){
  93. //console.log(items);
  94. /*for(vari=0;i<this.rowsPerPage;i++){
  95. if(items.length>i){
  96. this._addItem(items[i],i,true);
  97. }else{
  98. this._addItem({},0); background-color:inherit">}
  99. }*/
  100. dojo.forEach(items,function(item,idx){
  101. this._addItem(item,idx,153); font-weight:bold; background-color:inherit">this);
  102. this._autoHeight){
  103. this._skipRowRenormalize=true;
  104. this.updateRowCount(items.length);
  105. this.updateRows(0,items.length);
  106. this._autoHeight){
  107. false;
  108. if(req.isRender){
  109. this.setScrollTop(0);
  110. this.postrender();
  111. elsethis._lastScrollTop){
  112. this.setScrollTop(this._lastScrollTop);
  113. deletethis._lastScrollTop;
  114. this._isLoaded){
  115. this._isLoading=false;
  116. this._isLoaded=true;
  117. this._pending_requests[req.start]=//重写父类方法,初始化导航数字按钮
  118. _onFetchBegin:function(size,req){
  119. this._updateButtons(size);
  120. if(!size){
  121. this.views.render();
  122. this._resize();
  123. this.showMessage(this.noDataMessage);
  124. this.focus.initFocusView();
  125. return;
  126. this.showMessage();
  127. this.rowCount!=this.rowsPerPage){
  128. this.scroller.init(this.rowsPerPage,153); font-weight:bold; background-color:inherit">this.rowsPerPage);
  129. this.rowCount=this.rowsPerPage;
  130. this._setAutoHeightAttr(this.autoHeight,153); font-weight:bold; background-color:inherit">this.prerender();
  131. this.updateRowCount(this.rowsPerPage);
  132. _clearData:this.inherited(arguments);
  133. this.currentPage=1;
  134. this.totalPage=1;
  135. dojo.forEach(this._pageBtns,153); font-weight:bold; background-color:inherit">function(btn){
  136. btn.destroy();
  137. })
  138. this._firstBtn){
  139. this._prvIoUsBtn){
  140. this._nextBtn){
  141. this._lastBtn){
  142. this._pageLoaded= _updateButtons:function(size){
  143. //TODO先销毁按钮组
  144. this._pageBtns){
  145. dojo.forEach(function(element){
  146. element.destroy();
  147. })
  148. this._pageBtns=[];
  149. //初始化数字按钮条
  150. vartotalPage=(this.rowsPerPage?Math.ceil(size/this.rowsPerPage):size);
  151. varisShow=varisFirstRightDot=varisFirstLefttDot=varbeginIndex=4;
  152. for(vari=1;i<=totalPage;i++){
  153. if(i==1||i==2||i==totalPage||i==totalPage-1
  154. ||i==this.currentPage-1||i==this.currentPage-2
  155. ||i==this.currentPage+1||i==this.currentPage+2){
  156. isShow=this.currentPage==i){
  157. varnumBtn= label:i,248)"> baseClass:"",108); list-style:decimal-leading-zero outside; color:inherit; line-height:24px; margin:0px!important; padding:0px 3px 0px 10px!important"> tooltip:"第"+i+"页",248)"> style:{border:"1pxsolid#A8AAE2",margin:"1px"},108); list-style:decimal-leading-zero outside; color:inherit; line-height:24px; margin:0px!important; padding:0px 3px 0px 10px!important"> cssStateNodes:{"titleNode":"navi"},"_navigate",i)
  158. this._pageBtns.push(numBtn);
  159. numBtn.set('disabled',248)"> dojo.addClass(numBtn.domNode,'navi-selected');
  160. this._naviBar.addChild(numBtn,beginIndex);
  161. beginIndex++;
  162. if(isShow==true){
  163. label:i,108); list-style:decimal-leading-zero outside; color:inherit; line-height:24px; margin:0px!important; padding:0px 3px 0px 10px!important"> baseClass:"",248)"> tooltip:"第"+i+"页",108); list-style:decimal-leading-zero outside; color:inherit; line-height:24px; margin:0px!important; padding:0px 3px 0px 10px!important"> style:{border:"1pxsolid#A8AAE2",248)"> cssStateNodes:{"titleNode":"navi"},i)
  164. this._pageBtns.push(numBtn);
  165. beginIndex++;
  166. if(isFirstLefttDot==false&&i==this.currentPage-3){
  167. label:'...',108); list-style:decimal-leading-zero outside; color:inherit; line-height:24px; margin:0px!important; padding:0px 3px 0px 10px!important"> disabled: isFirstLefttDot=if(isFirstRightDot==false&&i>this.currentPage){
  168. label:'...',248)"> disabled: isFirstRightDot=/*varnumBtn=newdijit.form.Button({
  169. label:i+1,0); background-color:inherit">baseClass:"",0); background-color:inherit">tooltip:"第"+(i+1)+"页",0); background-color:inherit">style:{border:"1pxsolid#A8AAE2",margin:"1px"},0); background-color:inherit">cssStateNodes:{"titleNode":"navi"},0); background-color:inherit">onClick:dojo.hitch(this,"_navigate",i+1)
  170. });
  171. this._pageBtns.push(numBtn);
  172. this._naviBar.addChild(numBtn,i+4);
  173. this._naviBar.addChild(newdijit.form.Button({label:"...",baseClass:"",disabled:true}),btnsNum+3);
  174. varlasBtn=newdijit.form.Button({
  175. label:totalPage,0); background-color:inherit">tooltip:"第"+(totalPage)+"页",totalPage)
  176. })
  177. this._pageBtns.push(lasBtn);
  178. this._naviBar.addChild(lasBtn,btnsNum+4);
  179. this.totalPage=totalPage;
  180. //设置按钮的状态
  181. this._updateBtnStatus(this.currentPage);
  182. //this._pageLoaded=true;
  183. });
原文链接:https://www.f2er.com/dojo/291012.html

猜你在找的Dojo相关文章