/** * jQuery.bsgrid v1.38 by @Baishui2004 * Copyright 2014 Apache v2 License * https://github.com/baishui2004/jquery.bsgrid */ /** * require common.js. * * @author Baishui2004 * @Date August 31, 2014 */ (function ($) { $.fn.bsgrid_paging = { // defaults settings defaults: { loopback: false, // if true, page 1 prev then totalPages, totalPages next then 1 pageSize: 20, // page size pageSizeSelect: false, // if display pageSize select option pageSizeForGrid: [5, 10, 20, 25, 50, 100, 200, 500], // pageSize select option pageIncorrectTurnAlert: true, // if turn incorrect page alert(firstPage, prevPage, nextPage, lastPage) pagingLittleToolbar: false, // if display paging little toolbar pagingBtnClass: 'pagingBtn', // paging toolbar button css class pagingMinWidth: 'auto', // paging toolbar min-width, 'auto' means min-width by grid.paging.css, value example '300px' pagingBtnShowState: { // paging button show state, default show all select: true, first: true, prev: true, next: true, last: true, gotoBtn: true, // goto is keyword refresh: true } }, pagingObjs: {}, /** * init paging. */ init: function (pagingId, settings) { var options = { settings: $.extend(true, {}, $.fn.bsgrid_paging.defaults, settings), pagingId: pagingId, totalRowsId: pagingId + '_totalRows', totalPagesId: pagingId + '_totalPages', curPageId: pagingId + '_curPage', gotoPageInputId: pagingId + '_gotoPageInput', gotoPageId: pagingId + '_gotoPage', refreshPageId: pagingId + '_refreshPage', pageSizeId: pagingId + '_pageSize', firstPageId: pagingId + '_firstPage', prevPageId: pagingId + '_prevPage', nextPageId: pagingId + '_nextPage', lastPageId: pagingId + '_lastPage', startRowId: pagingId + '_startRow', endRowId: pagingId + '_endRow', totalRows: 0, totalPages: 0, curPage: 1, curPageRowsNum: 0, startRow: 0, endRow: 0 }; if (settings.pageSizeForGrid != undefined) { options.settings.pageSizeForGrid = settings.pageSizeForGrid; } var pagingObj = { options: options, page: function (curPage) { $.fn.bsgrid_paging.page(curPage, options); }, getCurPage: function () { return $.fn.bsgrid_paging.getCurPage(options); }, refreshPage: function () { $.fn.bsgrid_paging.refreshPage(options); }, firstPage: function () { $.fn.bsgrid_paging.firstPage(options); }, prevPage: function () { $.fn.bsgrid_paging.prevPage(options); }, nextPage: function () { $.fn.bsgrid_paging.nextPage(options); }, lastPage: function () { $.fn.bsgrid_paging.lastPage(options); }, gotoPage: function (goPage) { $.fn.bsgrid_paging.gotoPage(options, goPage); }, createPagingToolbar: function () { return $.fn.bsgrid_paging.createPagingToolbar(options); }, setPagingToolbarEvents: function () { $.fn.bsgrid_paging.setPagingToolbarEvents(options); }, dynamicChangePagingButtonStyle: function () { $.fn.bsgrid_paging.dynamicChangePagingButtonStyle(options); }, setPagingValues: function (curPage, totalRows) { $.fn.bsgrid_paging.setPagingValues(curPage, totalRows, options); } }; // store mapping paging id to pagingObj $.fn.bsgrid_paging.pagingObjs[pagingId] = pagingObj; $('#' + pagingId).append(pagingObj.createPagingToolbar()); // page size select if (options.settings.pageSizeSelect) { if ($.inArray(options.settings.pageSize, options.settings.pageSizeForGrid) == -1) { options.settings.pageSizeForGrid.push(options.settings.pageSize); } options.settings.pageSizeForGrid.sort(function (a, b) { return a - b; }); var optionsSb = new StringBuilder(); for (var i = 0; i < options.settings.pageSizeForGrid.length; i++) { var pageVal = options.settings.pageSizeForGrid[i]; optionsSb.append(''); } $('#' + options.pageSizeId).html(optionsSb.toString()).val(options.settings.pageSize); } pagingObj.setPagingToolbarEvents(); return pagingObj; }, getPagingObj: function (pagingId) { var obj = $.fn.bsgrid_paging.pagingObjs[pagingId]; return obj ? obj : null; }, page: function (curPage, options) { var gridObj = $.fn.bsgrid.getGridObj(options.settings.gridId); gridObj.options.settings.pageSize = options.settings.pageSize; $.fn.bsgrid.page(curPage, gridObj.options); }, getCurPage: function (options) { var curPage = $('#' + options.curPageId).html(); return curPage == '' ? 1 : curPage; }, refreshPage: function (options) { $.fn.bsgrid_paging.page($.fn.bsgrid_paging.getCurPage(options), options); }, firstPage: function (options) { var curPage = $.fn.bsgrid_paging.getCurPage(options); if (curPage <= 1) { $.fn.bsgrid_paging.incorrectTurnAlert(options, $.bsgridLanguage.isFirstPage); return; } $.fn.bsgrid_paging.page(1, options); }, prevPage: function (options) { var curPage = $.fn.bsgrid_paging.getCurPage(options); if (curPage <= 1) { if (options.settings.loopback && options.totalPages > 0) { $.fn.bsgrid_paging.page(options.totalPages, options); return; } else { $.fn.bsgrid_paging.incorrectTurnAlert(options, $.bsgridLanguage.isFirstPage); return; } } $.fn.bsgrid_paging.page(parseInt(curPage) - 1, options); }, nextPage: function (options) { var curPage = $.fn.bsgrid_paging.getCurPage(options); if (curPage >= options.totalPages) { if (options.settings.loopback && curPage > 0) { $.fn.bsgrid_paging.page(1, options); return; } else { $.fn.bsgrid_paging.incorrectTurnAlert(options, $.bsgridLanguage.isLastPage); return; } } $.fn.bsgrid_paging.page(parseInt(curPage) + 1, options); }, lastPage: function (options) { var curPage = $.fn.bsgrid_paging.getCurPage(options); if (curPage >= options.totalPages) { $.fn.bsgrid_paging.incorrectTurnAlert(options, $.bsgridLanguage.isLastPage); return; } $.fn.bsgrid_paging.page(options.totalPages, options); }, gotoPage: function (options, goPage) { if (goPage == undefined) { goPage = $('#' + options.gotoPageInputId).val(); } if ($.trim(goPage) == '' || isNaN(goPage)) { $.fn.bsgrid_paging.alert($.bsgridLanguage.needInteger); } else if (parseInt(goPage) < 1 || parseInt(goPage) > options.totalPages) { $.fn.bsgrid_paging.alert($.bsgridLanguage.needRange(1, options.totalPages)); } else { $('#' + options.gotoPageInputId).val(goPage); $.fn.bsgrid_paging.page(parseInt(goPage), options); } }, incorrectTurnAlert: function (options, msg) { if (options.settings.pageIncorrectTurnAlert) { $.fn.bsgrid_paging.alert(msg); } }, /** * alert message. * * @param msg message */ alert: function (msg) { try { $.bsgrid.alert(msg); } catch (e) { alert(msg); } }, /** * create paging toolbar. * * @param options */ createPagingToolbar: function (options) { var pagingSb = new StringBuilder(); var littleBar = options.settings.pagingLittleToolbar; pagingSb.append('
' + $.bsgridLanguage.pagingToolbar.pageSizeDisplay(options.pageSizeId, littleBar) + ' | '); } pagingSb.append('' + $.bsgridLanguage.pagingToolbar.currentDisplayRows(options.startRowId, options.endRowId, littleBar) + ' | '); pagingSb.append('' + $.bsgridLanguage.pagingToolbar.totalRows(options.totalRowsId) + ' | '); var btnClass = options.settings.pagingBtnClass; pagingSb.append(''); if (showStates.first) { pagingSb.append(''); } if (showStates.first && showStates.prev) { pagingSb.append(' '); } if (showStates.prev) { pagingSb.append(''); } pagingSb.append(' | '); pagingSb.append('' + $.bsgridLanguage.pagingToolbar.currentDisplayPageAndTotalPages(options.curPageId, options.totalPagesId) + ' | '); pagingSb.append(''); if (showStates.next) { pagingSb.append(''); } if (showStates.next && showStates.last) { pagingSb.append(' '); } if (showStates.last) { pagingSb.append(''); } pagingSb.append(' | '); if (showStates.gotoBtn) { pagingSb.append(''); pagingSb.append(''); pagingSb.append(' | '); pagingSb.append(''); pagingSb.append(''); pagingSb.append(' | '); } if (showStates.refresh) { pagingSb.append(''); pagingSb.append(''); pagingSb.append(' | '); } pagingSb.append('