vaeThink2/public/static/admin_static/lib/jquery.bsgrid/examples/layui/laypage-adapter.js

114 lines
3.8 KiB
JavaScript

/**
* laypage adapter for bsgrid.leer
*
* jQuery.bsgrid v1.37 by @Baishui2004
* Copyright 2014 Apache v2 License
* https://github.com/baishui2004/jquery.bsgrid
*/
/**
* require common.js, grid.js.
*
* @author Baishui2004
* @Date June 16, 2015
*/
$.fn.bsgrid.defaults.pageIncorrectTurnAlert = false;
$.fn.bsgrid.getCurPage = function (options) {
return options.curPage;
};
$.fn.bsgrid.refreshPage = function (options) {
$.fn.bsgrid.getGridObj(options.gridId).page($.fn.bsgrid.getCurPage(options));
};
$.fn.bsgrid.firstPage = function (options) {
$.fn.bsgrid.getGridObj(options.gridId).page(1);
};
$.fn.bsgrid.prevPage = function (options) {
var curPage = $.fn.bsgrid.getCurPage(options);
if (curPage <= 1) {
if (options.settings.pageIncorrectTurnAlert) {
alert($.bsgridLanguage.isFirstPage);
}
return;
}
$.fn.bsgrid.getGridObj(options.gridId).page(options.curPage - 1);
};
$.fn.bsgrid.nextPage = function (options) {
var curPage = $.fn.bsgrid.getCurPage(options);
if (curPage >= options.totalPages) {
if (options.settings.pageIncorrectTurnAlert) {
alert($.bsgridLanguage.isLastPage);
}
return;
}
$.fn.bsgrid.getGridObj(options.gridId).page(options.curPage + 1);
};
$.fn.bsgrid.lastPage = function (options) {
$.fn.bsgrid.getGridObj(options.gridId).page(options.totalPages);
};
$.fn.bsgrid.gotoPage = function (options, goPage) {
if (goPage == undefined) {
return;
}
if ($.trim(goPage) == '' || isNaN(goPage)) {
if (options.settings.pageIncorrectTurnAlert) {
alert($.bsgridLanguage.needInteger);
}
} else if (parseInt(goPage) < 1 || parseInt(goPage) > options.totalPages) {
if (options.settings.pageIncorrectTurnAlert) {
alert($.bsgridLanguage.needRange(1, options.totalPages));
}
} else {
$.fn.bsgrid.getGridObj(options.gridId).page(goPage);
}
};
$.fn.bsgrid.initPaging = function (options) {
$('#' + options.pagingOutTabId + ' td').append('<div id="' + options.pagingId + '" style="margin-top: 0px;"></div>');
$('#' + options.pagingOutTabId).css('border-width', '0');
};
$.fn.bsgrid.setPagingValues = function (options) {
laypage({
cont: options.pagingId,
pages: options.totalPages,
curr: options.curPage,
skip: true,
first: '首页',
last: '尾页',
jump: function (e, first) {
if (!first) {
$.fn.bsgrid.getGridObj(options.gridId).page(e.curr);
}
}
});
$.bsgrid.adaptAttrOrProp($('#' + options.pagingId + ' div span.laypage_total input.laypage_skip'), 'max', options.totalPages);
// page size select
if (options.settings.pageSizeSelect) {
$('#' + options.pagingId + '_pageSize').remove();
$('#' + options.pagingId + '>div').prepend('<span>每页显示:</span><select id="' + options.pagingId + '_pageSize' + '" style="height: 26px; padding:0 5px; margin-left: -8px; margin-right: 10px;"></select>');
var optionsSb = new StringBuilder();
for (var i = 0; i < options.settings.pageSizeForGrid.length; i++) {
var pageVal = options.settings.pageSizeForGrid[i];
optionsSb.append('<option value="' + pageVal + '">' + pageVal + '</option>');
}
$('#' + options.pagingId + '_pageSize').html(optionsSb.toString()).val(options.settings.pageSize);
// select change event
$('#' + options.pagingId + '_pageSize').change(function () {
options.settings.pageSize = parseInt($(this).val());
$(this).trigger('blur');
// if change pageSize, then page first
if (options.curPage == 1) {
$.fn.bsgrid.refreshPage(options);
} else {
$.fn.bsgrid.gotoPage(options, 1);
}
});
}
};