datatables的Bootstrap样式的分页怎么添加首页和尾页(引)
找到dataTables.bootstrap.js(版本3):(此项目中文件名为:dataTableExt.js)
$.fn.dataTableExt.oApi.fnPagingInfo = function ( oSettings )
{
return {
"iStart": oSettings._iDisplayStart,
"iEnd": oSettings.fnDisplayEnd(),
"iLength": oSettings._iDisplayLength,
"iTotal": oSettings.fnRecordsTotal(),
"iFilteredTotal": oSettings.fnRecordsDisplay(),
"iPage": oSettings._iDisplayLength === -1 ?
0 : Math.ceil( oSettings._iDisplayStart / oSettings._iDisplayLength ),
"iTotalPages": oSettings._iDisplayLength === -1 ?
0 : Math.ceil( oSettings.fnRecordsDisplay() / oSettings._iDisplayLength )
};
} /* Bootstrap style pagination control */
$.extend( $.fn.dataTableExt.oPagination, {
"bootstrap": {
"fnInit": function( oSettings, nPaging, fnDraw ) {
var oLang = oSettings.oLanguage.oPaginate;
var fnClickHandler = function ( e ) {
e.preventDefault();
if ( oSettings.oApi._fnPageChange(oSettings, e.data.action) ) {
fnDraw( oSettings );
}
}; $(nPaging).addClass('pagination').append(
'<ul>' +
'<li class="sFirst disabled"><a href="#"> ' + oLang.sFirst + '</a></li>' + //添加首页显示
'<li class="prev disabled"><a href="#"> ' + oLang.sPrevious + '</a></li>' + // '<li class="prev disabled"><a href="#">← '+oLang.sPrevious+'</a></li>'+
'<li class="next disabled"><a href="#">' + oLang.sNext + '</a></li>' + // '<li class="next disabled"><a href="#">'+oLang.sNext+' → </a></li>'+
'<li class="sLast disabled"><a href="#"> ' + oLang.sLast + '</a></li>' + //添加尾页显示
'</ul>'
);
var els = $('a', nPaging);
$(els[0]).bind('click.DT', { action: "first" }, fnClickHandler); //绑定首页事件
$(els[1]).bind('click.DT', { action: "previous" }, fnClickHandler);
$(els[2]).bind('click.DT', { action: "next" }, fnClickHandler);
$(els[3]).bind('click.DT', { action: "last" }, fnClickHandler);//绑定尾页事件
//$(els[0]).bind( 'click.DT', { action: "previous" }, fnClickHandler );
//$(els[1]).bind( 'click.DT', { action: "next" }, fnClickHandler );
}, "fnUpdate": function ( oSettings, fnDraw ) {
var iListLength = 5;
var oPaging = oSettings.oInstance.fnPagingInfo();
var an = oSettings.aanFeatures.p;
var i, j, sClass, iStart, iEnd, iHalf=Math.floor(iListLength/2); if ( oPaging.iTotalPages < iListLength) {
iStart = 1;
iEnd = oPaging.iTotalPages;
}
else if ( oPaging.iPage <= iHalf ) {
iStart = 1;
iEnd = iListLength;
} else if ( oPaging.iPage >= (oPaging.iTotalPages-iHalf) ) {
iStart = oPaging.iTotalPages - iListLength + 1;
iEnd = oPaging.iTotalPages;
} else {
iStart = oPaging.iPage - iHalf + 1;
iEnd = iStart + iListLength - 1;
} for ( i=0, iLen=an.length ; i<iLen ; i++ ) {
// Remove the middle elements
$('li:gt(1)', an[i]).filter(':lt(-2)').remove(); // 此处修改 $('li:gt(0)', an[i]).filter(':not(:last)').remove(); // Add the new list items and their event handlers
for ( j=iStart ; j<=iEnd ; j++ ) {
sClass = (j==oPaging.iPage+1) ? 'class="active"' : '';
$('<li '+sClass+'><a href="#">'+j+'</a></li>')
.insertBefore($('li:eq(-2)', an[i])[0])//此处修改 .insertBefore($('li:last', an[i])[0])
.bind('click', function (e) {
e.preventDefault();
oSettings._iDisplayStart = (parseInt($('a', this).text(),10)-1) * oPaging.iLength;
fnDraw( oSettings );
} );
} // Add / remove disabled classes from the static elements
if ( oPaging.iPage === 0 ) {
$('li:lt(2)', an[i]).addClass('disabled'); //此处修改 $('li:first', an[i]).addClass('disabled');
} else {
$('li:lt(2)', an[i]).removeClass('disabled'); //此处修改 $('li:first', an[i]).removeClass('disabled');
} if ( oPaging.iPage === oPaging.iTotalPages-1 || oPaging.iTotalPages === 0 ) {
$('li:gt(-3)', an[i]).addClass('disabled'); //此处修改 $('li:last', an[i]).addClass('disabled');
} else {
$('li:gt(-3)', an[i]).removeClass('disabled'); //此处修改 $('li:last', an[i]).removeClass('disabled');
}
}
}
}
} );
改之前显示效果:

改之后显示效果:

datatables的Bootstrap样式的分页怎么添加首页和尾页(引)的更多相关文章
- 问题: 在使用thinkphp自带分页类时,在设置尾页显示的最后一页时,用setConfig(“last”,”尾页”)来设置样式,发现无效。
分析: 在分页类(/ThinkPHP/Library/Think/Page.class.PHP)里面有一个共有属性: public $lastSuffix = true; // 最后一页是否显示总页数 ...
- datatables 配套bootstrap样式使用小结(2) ajax篇
距离上一篇有点时间了,周末做了伴郎参加了一个土豪同学的婚礼. 上一篇是介绍一下基本的用法,基本的原理是取出所有的数据,然后调用$.datatables(option)方法格式化,这种方法显然不太科学, ...
- 高仿bootstrap样式的分页插件
链接:https://pan.baidu.com/s/1jKgn2hK 密码:whwl 不知道是自己的第几个分页插件了,以前写一个丢一个,桌面,U盘,移动硬盘.想用的时候找不到,这次传网上来.大家帮忙 ...
- pagination分页(支持首页,末页,跳转)
最近在用jq做分页,大致的效果如下: jquery.pagination.js插件说明 用法如下: 1.引入jq.jquery.pagination.js.pagination.css 2.在页面上写 ...
- Python - Django - 添加首页尾页上一页下一页
添加首页和尾页: views.py: from django.shortcuts import render from app01 import models def book_list(reques ...
- datatables 配套bootstrap3样式使用小结(1)
今天介绍汇总一下datatables. 网址: www.datatables.net 公司CMS内容资讯站的后台管理界面用了大量的table来管理数据,试用了之后,感觉挺不错,推荐一下. 先上一个基本 ...
- DataTables ajax + bootstrap 分页/搜索/排序/常见问题
最近学校的网站建设需要,尝试使用了下Jquery dataTables控件,接触过C#的人都知道,C#中也含有一个DataTable,但它和我们今天讨论的东西无关 我使用的是官网最新的DataTabl ...
- Bootstrap -- 导航栏样式、分页样式、标签样式、徽章样式
Bootstrap -- 导航栏样式.分页样式.标签样式.徽章样式 1. 使用图标的导航栏 使用导航栏样式: <!DOCTYPE html> <html> <head&g ...
- jqgrid+bootstrap样式实践
jqgrid+bootstrap样式实践,报错数据加载,选中,删除等功能 需要引入的样式 bootstrap.min.css ui.jqgrid.css 需要引入的JS jquery.min.js b ...
随机推荐
- Testing the CATCHER_DP
Description A military contractor for the Department of Defense has just completed a series of preli ...
- .a包生成64位
./configure CC="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain ...
- java学习第六天
目标 1. 块 2. GC(了解) 3. package import 4. 封装 一.块 {} 分类 1.普通块 作用: 组织代码.解决变量的作用域.节约了内存. 在同一个作用域内,不能声 ...
- 让IE9支持html5
IE10以上才算是真正支持了html5 ,但仍然有些地方和别的浏览器不一致,比如要在js里移除一个html标签, 如果是IE,document.getElementById("a" ...
- Sublime Text插件:HTML+CSS+JAVASCRIPT+JSON快速格式化
安装过程简要说明如下: 在Sublime Text中,按下Ctrl+Shift+P调出命令面板; 输入install 调出 Install Package 选项并回车; 输入pretty,并在列表中选 ...
- C. Polycarpus' Dice
在每个位置讨论一下最大值最小值的取值范围就行 #include<cstdio> #include<iostream> #define maxn 200003 using nam ...
- hdu 2334 March of the Penguins
题意大意 在X,Y坐标系中有N(N<=100)个冰块,有些冰块上有1若干只企鹅,每只企鹅一次最多跳M距离,一个冰块在有Mi个企鹅离开,就会消失,问有哪些冰块可以作为集合点,就是所有企鹅都能成 ...
- tyvj 1402 dp
P1402 [NOIP2010]乌龟棋 时间: 1000ms / 空间: 131072KiB / Java类名: Main 背景 NOIP2010提高组复赛第二题 描述 小明过生日的时候,爸爸送给他一 ...
- Codeforces Round #366 (Div. 2) C 模拟queue
C. Thor time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...
- Color Map的生成方法
/* Return a RGB colour value given a scalar v in the range [vmin,vmax] In this case each colour comp ...