Pager
jQuery
var Pager = function (ops) {
this._ops = {
count: ops.count || 0,
selectedIndex: ops.selectedIndex || 1,
size: ops.size || 0
};
this._element = ops.element || document.getElementsByTagName('body');
this._init()
._create()
._initMember()
._createPagerBtn()
._initEventBind()
this._inputValue = 1;
};
Pager.prototype = {
_initId: function () {
uuid++;
this._pagerId = "ui-pager-" + uuid;
},
_init: function () {
this._element.id = this._pagerId;
$(this._element).addClass('ui-pager-container')
return this;
},
_create: function () {
var fragement = [], h = -1;
fragement[++h] = "<div class=\"ui-pager-trangleBtn\">";
fragement[++h] = "<button class=\"ui-pager-triangle-left-as\"></button>";
fragement[++h] = "</div>";
fragement[++h] = "<div class=\"pager-content\">";
fragement[++h] = "</div>";
fragement[++h] = "<div class=\"ui-pager-trangleBtn\">";
fragement[++h] = "<button class=\"ui-pager-triangle-right-as\"></button>";
fragement[++h] = "</div>";
fragement[++h] = "<div class=\"ui-pager-go\">";
fragement[++h] = "<input type=\"text\" class=\"ui-pager-go-input\" value=\"1\" />";
fragement[++h] = "<button class=\"ui-pager-go-btn\">GO</button>";
fragement[++h] = "</div>";
$(this._element).append(fragement.join(''));
return this;
},
_createPagerBtn: function () {
this.$pagerElBtnGroup.empty();
var
fragement = [], h = -1;
if (this._ops.count <= 5) {
for (var i = 0; i < this._ops.count; i++) {
if (i + 1 == this._ops.selectedIndex)
fragement[++h] = "<button class=\"pager-content-btn active\" value=" + (i + 1) + ">";
else
fragement[++h] = "<button class=\"pager-content-btn\" value=" + (i + 1) + ">";
fragement[++h] = i + 1;
fragement[++h] = "</button>";
}
this.$pagerElBtnGroup.append(fragement.join(''));
} else {
for (var i = 0; i < this._ops.count; i++) {
if (this._ops.selectedIndex <= 4 || this._ops.selectedIndex == this._ops.count) {
if (i + 1 <= 4) {
if (i + 1 == this._ops.selectedIndex)
fragement[++h] = "<button class=\"pager-content-btn active\" value=" + (i + 1) + "> " + (i + 1) + "</button>";
else
fragement[++h] = "<button class=\"pager-content-btn\" value=" + (i + 1) + ">" + (i + 1) + "</button>";
} else if (i + 1 == this._ops.count) {
var m = h + 1;
if (i + 1 == this._ops.selectedIndex)
fragement[++m] = "<button class=\"pager-content-btn active\" value=" + (i + 1) + "> " + (i + 1) + "</button>";
else
fragement[++m] = "<button class=\"pager-content-btn\" value=" + (i + 1) + ">" + (i + 1) + "</button>";
} else {
fragement[h + 1] = "<button class=\"button-bald\" disabled>...</button>";
}
} else if (this._ops.selectedIndex == 1 || this._ops.selectedIndex >= this._ops.count - 3) {
if (i + 1 == 1) {
if (i + 1 == this._ops.selectedIndex)
fragement[++h] = "<button class=\"pager-content-btn active\" value=" + (i + 1) + "> " + (i + 1) + "</button>";
else
fragement[++h] = "<button class=\"pager-content-btn\" value=" + (i + 1) + ">" + (i + 1) + "</button>";
} else if (i + 1 >= this._ops.count - 3) {
var m = h + 1;
if (i + 1 == this._ops.selectedIndex)
fragement[++m] = "<button class=\"pager-content-btn active\" value=" + (i + 1) + "> " + (i + 1) + "</button>";
else
fragement[++m] = "<button class=\"pager-content-btn\" value=" + (i + 1) + ">" + (i + 1) + "</button>";
h = m;
} else {
fragement[h + 1] = "<button class=\"button-bald\" disabled>...</button>";
}
} else if (this._ops.selectedIndex > 4 && this._ops.selectedIndex < this._ops.count - 3) {
if (i + 1 == 1) {
if (i + 1 == this._ops.selectedIndex)
fragement[++h] = "<button class=\"pager-content-btn active\" value=" + (i + 1) + "> " + (i + 1) + "</button>";
else
fragement[++h] = "<button class=\"pager-content-btn\" value=" + (i + 1) + "> " + (i + 1) + "</button>";
} else if (i + 1 == this._ops.selectedIndex - 1 || i + 1 == this._ops.selectedIndex || i + 1 == this._ops.selectedIndex + 1) {
var m = h + 1;
if (i + 1 == this._ops.selectedIndex)
fragement[++m] = "<button class=\"pager-content-btn active\" value=" + (i + 1) + "> " + (i + 1) + "</button>";
else
fragement[++m] = "<button class=\"pager-content-btn\" value=" + (i + 1) + "> " + (i + 1) + "</button>";
h = m;
} else if (i + 1 == this._ops.count) {
var m = h + 1;
if (i + 1 == this._ops.selectedIndex)
fragement[++m] = "<button class=\"pager-content-btn active\" value=" + (i + 1) + "> " + (i + 1) + "</button>";
else
fragement[++m] = "<button class=\"pager-content-btn\" value=" + (i + 1) + "> " + (i + 1) + "</button>";
h = m;
} else {
fragement[h + 1] = "<button class=\"button-bald\" disabled>...</button>";
}
}
}
this.$pagerElBtnGroup.append(fragement.join(''));
}
return this;
},
_initMember: function () {
this.$leftBtn = $("#" + this._pagerId + " .ui-pager-triangle-left-as");
this.$rightBtn = $("#" + this._pagerId + " .ui-pager-triangle-right-as");
this.$goBtn = $("#" + this._pagerId + " .ui-pager-go-btn");
this.$pagerElBtnGroup = $("#" + this._pagerId + " .pager-content");
this.$input = $("#" + this._pagerId + " .ui-pager-go-input");
return this;
},
_initEventBind() {
this.$leftBtn.on('click', this._leftBtnClick.bind(this));
this.$rightBtn.on('click', this._rightBtnClick.bind(this));
this.$goBtn.on('click', this._goBtnClick.bind(this));
this.$pagerElBtnGroup.on('click', this._pageBtnClick.bind(this));
},
_leftBtnClick: function () {
if (this._ops.selectedIndex != 1)
this._ops.selectedIndex -= 1;
else
return;
this._setSelectIndex(this._ops.selectedIndex);
},
_rightBtnClick: function () {
if (this._ops.selectedIndex != this._ops.count)
this._ops.selectedIndex += 1;
else
return;
this._setSelectIndex(this._ops.selectedIndex);
},
_pageBtnClick: function (e) {
var
selectedIndex = parseInt(e.target.value);
this._setSelectIndex(selectedIndex);
},
_goBtnClick: function () {
var value = this.$input.val();
if (value == '') throw new Error('Value i error.');
var targetIndex = parseInt(value);
this._setSelectIndex(targetIndex);
},
_setSelectIndex: function (index) {
var selectedIndex = index || 1;
var $element = $(this._element);
$$.trigger("selectedPageChanged", $element, $$.Event({
element: $element,
oldValue: null,
newValue: selectedIndex
}));
this._ops.selectedIndex = selectedIndex;
this._createPagerBtn();
},
React
import ReactWidget from '../react-widget';
class Pager extends ReactWidget {
constructor(props) {
super(props);
}
componentWillReceiveProps(newProps) {
//this.element.setOptions({
// items: newProps.items,
// selectedIndex: newProps.selectedIndex
//});
}
componentDidMount() {
this.element = new aui.Pager({
element: ReactDOM.findDOMNode(this),
size: this.props.pageSize,
count: this.props.pageCount,
selectedIndex: this.props.selectedPage
});
$(ReactDOM.findDOMNode(this)).on('selectedPageChanged', this.props.selectedPageChanged.bind(this));
}
render() {
return <div>
</div>
}
}
window.$$.Pager = Pager;
less
.ui-pager-container {
.ui-pager-trangleBtn {
display: inline-block;
margin: 0 10px;
& > button {
padding: 5px;
border-radius: 10px;
}
.ui-pager-triangle-left-as {
&::before {
content: '\25C4'
}
}
.ui-pager-triangle-right-as {
&::before {
content: '\25BA'
}
}
}
.pager-content {
display: inline-block;
& > button {
padding: 5px 8px;
margin: 0 5px;
}
.button-bald {
border: 0;
background: 0 0;
}
.active {
background: #9D9D9D;
color: #fff;
}
}
.ui-pager-go {
display: inline-block;
.ui-pager-go-input {
display: inline-block;
width: 20px;
padding: 5px;
}
.ui-pager-go-btn {
margin: 0 10px;
padding: 5px;
}
}
}
样式:

Pager的更多相关文章
- MVC如何使用开源分页插件shenniu.pager.js
最近比较忙,前期忙公司手机端接口项目,各种开发+调试+发布现在几乎上线无问题了:虽然公司项目忙不过在期间抽空做了两件个人觉得有意义的事情,一者使用aspnetcore开发了个人线上项目(要说线上其实只 ...
- 自己写的一个Pager分页组件,WebForm,Mvc都适用
我一说写这个功能的时候,好多人估计有疑问.分页功能网上多的是,搜一个不就行了,你这样不是浪费时间么.你说这句话的时候,我是比较信的,首先自己写一些东西是很耗时,有这些时间又能多打几盘LOL了.但是我觉 ...
- 用jquery.pager.js实现分页
1.html <link href="/stylesheets/Pager.css" rel="stylesheet" type="text/c ...
- asp.net mvc 自定义pager封装与优化
asp.net mvc 自定义pager封装与优化 Intro 之前做了一个通用的分页组件,但是有些不足,从翻页事件和分页样式都融合在后台代码中,到翻页事件可以自定义,再到翻页和样式都和代码分离, 自 ...
- asp.net mvc 简易通用自定义Pager实现分页
asp.net mvc 自定义Pager实现分页 Intro 一个WEB应用程序中经常会用到数据分页,本文将实现一个简单通用的分页组件,包含一个 PagerModel (用来保存页码信息),一个 Ht ...
- SQLite学习笔记(九)&&pager模块
概述 通过上一篇文章的分析,我们知道了pager模块在整个sqlite中所处的位置.它是sqlite的核心模块,充当了多种重要角色.作为一个事务管理器,它通过并发控制和故障恢复实现事务的ACID特性, ...
- Web jquery表格组件 JQGrid 的使用 - 5.Pager翻页、搜索、格式化、自定义按钮
系列索引 Web jquery表格组件 JQGrid 的使用 - 从入门到精通 开篇及索引 Web jquery表格组件 JQGrid 的使用 - 4.JQGrid参数.ColModel API.事件 ...
- Web jquery表格组件 JQGrid 的使用 - 8.Pager、新增数据、查询、刷新、查看数据
系列索引 Web jquery表格组件 JQGrid 的使用 - 从入门到精通 开篇及索引 Web jquery表格组件 JQGrid 的使用 - 4.JQGrid参数.ColModel API.事件 ...
- PHP通用分页(Pager)类
三种不同展示方式 附上style~ 1. 效果图1 2.效果图2 3. 效果图3 4. 分页类主体 <?php /** * PHP通用分页类 * show(2) 1 ... 62 63 6 ...
- Last time, I wrote a pager, but now it seems this no longer has use, so I want to paste it here.
public class Pager<T> where T : new() { private IEnumerable<T> _all; private IEnumerable ...
随机推荐
- Permute Digits
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to con ...
- PCRE does not support \L, \l, \N{name}, \U, or \u...
PCRE does not support \L, \l, \N{name}, \U, or \u... 参考文章:YCSUNNYLIFE 的 <php 正则匹配中文> 一.报错情景: 使 ...
- python 反射、动态导入
1. 反射 hasattr(obj,'name') # 判断对象中是否含有字符串形式的方法名或属性名,返回True.False getattr(obj,'name',None) ...
- 曙光浪潮IBM驱动
https://pan.baidu.com/s/1lDrotg5jpdN_z0yOYyAo4w
- 解决IDEA Initialization error 'https://start.spring.io'
IDEA Initialization error 'https://start.spring.io' 弹出一个error窗口 就是不能连接https://start.spring.i ...
- jsp页面实现上传文件,并且还得支持断点续传的功能
我们平时经常做的是上传文件,上传文件夹与上传文件类似,但也有一些不同之处,这次做了上传文件夹就记录下以备后用. 首先我们需要了解的是上传文件三要素: 1.表单提交方式:post (get方式提交有大小 ...
- POJ 2182 Lost Cows (树状数组 && 二分查找)
题意:给出数n, 代表有多少头牛, 这些牛的编号为1~n, 再给出含有n-1个数的序列, 每个序列的数 ai 代表前面还有多少头比 ai 编号要小的牛, 叫你根据上述信息还原出原始的牛的编号序列 分析 ...
- css实现不定宽高的div水平、垂直居中
一共有三个方案: 1,第一种方案主要使用了css3中transform进行元素偏移,效果非常好 这方法功能很强大,也比较灵活,不仅仅局限在实现居中显示. 兼容方面也一样拿IE来做比较,第二种方法IE ...
- [Codeforce526F]:Pudding Monsters(分治)
题目传送门 题目描述 由于各种原因,桐人现在被困在Under World(以下简称UW)中,而UW马上要迎来最终的压力测试——魔界入侵.唯一一个神一般存在的Administrator被消灭了,靠原本的 ...
- 关于MySQL 中 EXISTS 的用法
在MySQL中 EXISTS 和 IN 的用法有什么关系和区别呢? 假定数据库中有两个表 分别为 表 a 和表 b create table a ( a_id int, a_name varchar( ...