6 lines
7.9 KiB
JavaScript
6 lines
7.9 KiB
JavaScript
/**
|
|
* jQuery.bsgrid v1.38 by @Baishui2004
|
|
* Copyright 2014 Apache v2 License
|
|
* https://github.com/baishui2004/jquery.bsgrid
|
|
*/
|
|
(function(a){a.fn.bsgrid_paging={defaults:{loopback:false,pageSize:20,pageSizeSelect:false,pageSizeForGrid:[5,10,20,25,50,100,200,500],pageIncorrectTurnAlert:true,pagingLittleToolbar:false,pagingBtnClass:"pagingBtn",pagingMinWidth:"auto",pagingBtnShowState:{select:true,first:true,prev:true,next:true,last:true,gotoBtn:true,refresh:true}},pagingObjs:{},init:function(h,g){var d={settings:a.extend(true,{},a.fn.bsgrid_paging.defaults,g),pagingId:h,totalRowsId:h+"_totalRows",totalPagesId:h+"_totalPages",curPageId:h+"_curPage",gotoPageInputId:h+"_gotoPageInput",gotoPageId:h+"_gotoPage",refreshPageId:h+"_refreshPage",pageSizeId:h+"_pageSize",firstPageId:h+"_firstPage",prevPageId:h+"_prevPage",nextPageId:h+"_nextPage",lastPageId:h+"_lastPage",startRowId:h+"_startRow",endRowId:h+"_endRow",totalRows:0,totalPages:0,curPage:1,curPageRowsNum:0,startRow:0,endRow:0};if(g.pageSizeForGrid!=undefined){d.settings.pageSizeForGrid=g.pageSizeForGrid}var b={options:d,page:function(i){a.fn.bsgrid_paging.page(i,d)},getCurPage:function(){return a.fn.bsgrid_paging.getCurPage(d)},refreshPage:function(){a.fn.bsgrid_paging.refreshPage(d)},firstPage:function(){a.fn.bsgrid_paging.firstPage(d)},prevPage:function(){a.fn.bsgrid_paging.prevPage(d)},nextPage:function(){a.fn.bsgrid_paging.nextPage(d)},lastPage:function(){a.fn.bsgrid_paging.lastPage(d)},gotoPage:function(i){a.fn.bsgrid_paging.gotoPage(d,i)},createPagingToolbar:function(){return a.fn.bsgrid_paging.createPagingToolbar(d)},setPagingToolbarEvents:function(){a.fn.bsgrid_paging.setPagingToolbarEvents(d)},dynamicChangePagingButtonStyle:function(){a.fn.bsgrid_paging.dynamicChangePagingButtonStyle(d)},setPagingValues:function(j,i){a.fn.bsgrid_paging.setPagingValues(j,i,d)}};a.fn.bsgrid_paging.pagingObjs[h]=b;a("#"+h).append(b.createPagingToolbar());if(d.settings.pageSizeSelect){if(a.inArray(d.settings.pageSize,d.settings.pageSizeForGrid)==-1){d.settings.pageSizeForGrid.push(d.settings.pageSize)}d.settings.pageSizeForGrid.sort(function(j,i){return j-i});var f=new StringBuilder();for(var e=0;e<d.settings.pageSizeForGrid.length;e++){var c=d.settings.pageSizeForGrid[e];f.append('<option value="'+c+'">'+c+"</option>")}a("#"+d.pageSizeId).html(f.toString()).val(d.settings.pageSize)}b.setPagingToolbarEvents();return b},getPagingObj:function(c){var b=a.fn.bsgrid_paging.pagingObjs[c];return b?b:null},page:function(c,b){var d=a.fn.bsgrid.getGridObj(b.settings.gridId);d.options.settings.pageSize=b.settings.pageSize;a.fn.bsgrid.page(c,d.options)},getCurPage:function(b){var c=a("#"+b.curPageId).html();return c==""?1:c},refreshPage:function(b){a.fn.bsgrid_paging.page(a.fn.bsgrid_paging.getCurPage(b),b)},firstPage:function(b){var c=a.fn.bsgrid_paging.getCurPage(b);if(c<=1){a.fn.bsgrid_paging.incorrectTurnAlert(b,a.bsgridLanguage.isFirstPage);return}a.fn.bsgrid_paging.page(1,b)},prevPage:function(b){var c=a.fn.bsgrid_paging.getCurPage(b);if(c<=1){if(b.settings.loopback&&b.totalPages>0){a.fn.bsgrid_paging.page(b.totalPages,b);return}else{a.fn.bsgrid_paging.incorrectTurnAlert(b,a.bsgridLanguage.isFirstPage);return}}a.fn.bsgrid_paging.page(parseInt(c)-1,b)},nextPage:function(b){var c=a.fn.bsgrid_paging.getCurPage(b);if(c>=b.totalPages){if(b.settings.loopback&&c>0){a.fn.bsgrid_paging.page(1,b);return}else{a.fn.bsgrid_paging.incorrectTurnAlert(b,a.bsgridLanguage.isLastPage);return}}a.fn.bsgrid_paging.page(parseInt(c)+1,b)},lastPage:function(b){var c=a.fn.bsgrid_paging.getCurPage(b);if(c>=b.totalPages){a.fn.bsgrid_paging.incorrectTurnAlert(b,a.bsgridLanguage.isLastPage);return}a.fn.bsgrid_paging.page(b.totalPages,b)},gotoPage:function(b,c){if(c==undefined){c=a("#"+b.gotoPageInputId).val()}if(a.trim(c)==""||isNaN(c)){a.fn.bsgrid_paging.alert(a.bsgridLanguage.needInteger)}else{if(parseInt(c)<1||parseInt(c)>b.totalPages){a.fn.bsgrid_paging.alert(a.bsgridLanguage.needRange(1,b.totalPages))}else{a("#"+b.gotoPageInputId).val(c);a.fn.bsgrid_paging.page(parseInt(c),b)}}},incorrectTurnAlert:function(b,c){if(b.settings.pageIncorrectTurnAlert){a.fn.bsgrid_paging.alert(c)}},alert:function(c){try{a.bsgrid.alert(c)}catch(b){alert(c)}},createPagingToolbar:function(b){var e=new StringBuilder();var c=b.settings.pagingLittleToolbar;e.append('<table class="bsgridPaging'+(c?" pagingLittleToolbar":"")+(b.settings.pageSizeSelect?"":" noPageSizeSelect")+'"');if(b.settings.pagingMinWidth!="auto"){e.append(' style="width: '+b.settings.pagingMinWidth+' !important"')}e.append(">");e.append("<tr>");var f=b.settings.pagingBtnShowState;if(b.settings.pageSizeSelect&&f.select){e.append("<td>"+a.bsgridLanguage.pagingToolbar.pageSizeDisplay(b.pageSizeId,c)+"</td>")}e.append("<td>"+a.bsgridLanguage.pagingToolbar.currentDisplayRows(b.startRowId,b.endRowId,c)+"</td>");e.append("<td>"+a.bsgridLanguage.pagingToolbar.totalRows(b.totalRowsId)+"</td>");var d=b.settings.pagingBtnClass;e.append("<td>");if(f.first){e.append('<input class="'+d+' firstPage" type="button" id="'+b.firstPageId+'" value="'+(c?"":a.bsgridLanguage.pagingToolbar.firstPage)+'" />')}if(f.first&&f.prev){e.append(" ")}if(f.prev){e.append('<input class="'+d+' prevPage" type="button" id="'+b.prevPageId+'" value="'+(c?"":a.bsgridLanguage.pagingToolbar.prevPage)+'" />')}e.append("</td>");e.append("<td>"+a.bsgridLanguage.pagingToolbar.currentDisplayPageAndTotalPages(b.curPageId,b.totalPagesId)+"</td>");e.append("<td>");if(f.next){e.append('<input class="'+d+' nextPage" type="button" id="'+b.nextPageId+'" value="'+(c?"":a.bsgridLanguage.pagingToolbar.nextPage)+'" />')}if(f.next&&f.last){e.append(" ")}if(f.last){e.append('<input class="'+d+' lastPage" type="button" id="'+b.lastPageId+'" value="'+(c?"":a.bsgridLanguage.pagingToolbar.lastPage)+'" />')}e.append("</td>");if(f.gotoBtn){e.append('<td class="gotoPageInputTd">');e.append('<input class="gotoPageInput" type="text" id="'+b.gotoPageInputId+'" />');e.append("</td>");e.append('<td class="gotoPageButtonTd">');e.append('<input class="'+d+' gotoPage" type="button" id="'+b.gotoPageId+'" value="'+(c?"":a.bsgridLanguage.pagingToolbar.gotoPage)+'" />');e.append("</td>")}if(f.refresh){e.append('<td class="refreshPageTd">');e.append('<input class="'+d+' refreshPage" type="button" id="'+b.refreshPageId+'" value="'+(c?"":a.bsgridLanguage.pagingToolbar.refreshPage)+'" />');e.append("</td>")}e.append("</tr>");e.append("</table>");return e.toString()},setPagingToolbarEvents:function(b){if(b.settings.pageSizeSelect){a("#"+b.pageSizeId).change(function(){b.settings.pageSize=parseInt(a(this).val());a(this).trigger("blur");a.fn.bsgrid_paging.page(1,b)})}a("#"+b.firstPageId).click(function(){a.fn.bsgrid_paging.firstPage(b)});a("#"+b.prevPageId).click(function(){a.fn.bsgrid_paging.prevPage(b)});a("#"+b.nextPageId).click(function(){a.fn.bsgrid_paging.nextPage(b)});a("#"+b.lastPageId).click(function(){a.fn.bsgrid_paging.lastPage(b)});a("#"+b.gotoPageInputId).keyup(function(c){if(c.which==13){a.fn.bsgrid_paging.gotoPage(b)}});a("#"+b.gotoPageId).click(function(){a.fn.bsgrid_paging.gotoPage(b)});a("#"+b.refreshPageId).click(function(){a.fn.bsgrid_paging.refreshPage(b)})},dynamicChangePagingButtonStyle:function(b){var c="disabledCls";if(b.curPage<=1){a("#"+b.firstPageId).addClass(c);a("#"+b.prevPageId).addClass(c)}else{a("#"+b.firstPageId).removeClass(c);a("#"+b.prevPageId).removeClass(c)}if(b.curPage>=b.totalPages){a("#"+b.nextPageId).addClass(c);a("#"+b.lastPageId).addClass(c)}else{a("#"+b.nextPageId).removeClass(c);a("#"+b.lastPageId).removeClass(c)}},setPagingValues:function(i,g,f){i=Math.max(i,1);var b=f.settings.pageSize;var h=parseInt(g/b);h=parseInt((g%b==0)?h:h+1);var e=(i*b<g)?b:(g-(i-1)*b);var d=(i-1)*b+1;var c=d+e-1;d=e<=0?0:d;c=e<=0?0:c;f.totalRows=g;f.totalPages=h;f.curPage=i;f.curPageRowsNum=e;f.startRow=d;f.endRow=c;a("#"+f.totalRowsId).html(f.totalRows);a("#"+f.totalPagesId).html(f.totalPages);a("#"+f.curPageId).html(f.curPage);a("#"+f.startRowId).html(f.startRow);a("#"+f.endRowId).html(f.endRow);a.fn.bsgrid_paging.dynamicChangePagingButtonStyle(f)}}})(jQuery); |