SharePoint2013 SharePoint-Hosted 模式 分页方法
/**分页js插件
var ListPager = new listPaging();
先调用start方法加载上下文
然后调用dataLoad方法查询第一页数据
需要设置几个属性值
ListPager.property.pageSize = 4;
ListPager.start();
ListPager.property.prevControlID = "prevBtn";//上一页按钮id
ListPager.property.nextControlID = "nextBtn";//下一页按钮id
ListPager.property.controlActionType = "css";//操作类型attr为禁用 css为显示隐藏
然后在success这个成功回调的函数中设置上一页的状态
var id = ListPager.property.listItems.itemAt(0).get_id();
ListPager.property.PagingState = ["p_ID=" + id];
p_ID是必填项。否则无法返回上一页
如果查询的数据 需要排序需要在PagingState的数组中添加你的排序字段
例如:var title = ListPager.property.listItems.itemAt(0).get_item("Title");
ListPager.property.PagingState = ["p_ID=" + id,"p_Title="+title];
如果排序字段为时间类型,比如2013-01-01 请转成20130101
分页方法调用:ListPager.getListPager
*/
var listPaging = function () { };
listPaging.prototype={
property: {
clientContext:null,
webSite : null,
siteUrl:"",
listItems : null,
query : null,
targetList : null,
position : null,
lastState : null,
pageState : "",
itemIndex : 1,
pageIndex : 1,
pageSize : 15,
prevControlID : "",
nextControlID : "",
PagingState:null,//Array 格式 ["key=value","key1=value1"],value 为时间格式的话,比如2013-01-01 请转成20130101
/* @ControlActionType: 分页操作控件启用和禁用的方式css/attr。*/
controlActionType : "css"
},
start:function(){
this.property.clientContext = new SP.ClientContext.get_current();
this.property.webSite = this.property.clientContext.get_web();
},
/*加载列表数据*/
/**
* @listName: 列表名称。
* @camlQuery: Caml语句
* @isUserList: 是不是用户列表true/false
* @success: 成功执行方法。
* @error: 失败执行方法
*/
dataLoad: function (listName, camlQuery, isUserList,success, error) {
this.property.pageIndex = 1;
this.property.pageState = "";
if (isUserList)
this.property.targetList = this.property.webSite.get_siteUserInfoList();
else
this.property.targetList = this.property.webSite.get_lists().getByTitle(listName);
this.property.query = new SP.CamlQuery();
this.property.query.set_viewXml(camlQuery);
this.property.listItems = this.property.targetList.getItems(this.property.query);
this.property.clientContext.load(this.property.listItems);
this.property.clientContext.executeQueryAsync(Function.createDelegate(this, success), Function.createDelegate(this, error));
},
getListPager:function (result, camlQuery, success, error) {
this.property.pageState = result;
this.property.lastState = this.property.position;//保存当前页的状态
if (this.property.pageState == "prev") {//上一页
this.property.itemIndex = this.property.itemIndex - (this.property.listItems.get_count() + this.property.pageSize);
if (this.property.position == null) {
this.property.position = new SP.ListItemCollectionPosition();
}
var prevPageString = this.property.position.get_pagingInfo();
var prevString = "PagedPrev=TRUE";
var searchStr = prevPageString.split("&");
for (var i = 0; i < searchStr.length; i++) {
var key = searchStr[i].split("=")[0];
var value = searchStr[i].split("=")[1];
for (var p = 0; p < this.property.PagingState.length; p++) {
var state = this.property.PagingState[p].split("=");
if (key == state[0]) {
value = state[1];
}
}
prevString += "&"+key+"="+value;
}
this.property.position.set_pagingInfo(prevString);//设置上一页读取状态
this.property.pageIndex--;
if (this.property.pageIndex == 1) {//如果到第一页,上一页禁用
//删除下一页的禁用状态
if (this.property.controlActionType == "css") {
$("#" + this.property.prevControlID).css("display", "none");
$("#" + this.property.nextControlID).css("display", "block");
}
if (this.property.controlActionType == "attr") {
$("#" + this.property.nextControlID).removeAttr("disabled");
$("#" + this.property.prevControlID).attr("disabled", "disabled");
}
}
else {
if (this.property.controlActionType == "css") {
$("#" + this.property.nextControlID).css("display", "block");
}
if (this.property.controlActionType == "attr") {
$("#" + this.property.nextControlID).removeAttr("disabled");
}
}
}
else {//下一页
if (this.property.position == null)
this.property.position = this.property.lastState;//赋值上一页状态
if (this.property.controlActionType == "css")
$("#" + this.property.prevControlID).css("display", "block");
if (this.property.controlActionType == "attr")
$("#" + this.property.prevControlID).removeAttr("disabled");
//var prevPageString = this.property.position.get_pagingInfo();
//prevPageString = prevPageString.replace("PagedPrev", "Paged");
//this.property.position.set_pagingInfo(prevPageString);//设置上一页读取状态
this.property.pageIndex++;
}
this.property.query = new SP.CamlQuery();
this.property.query.set_viewXml(camlQuery);
this.property.query.set_listItemCollectionPosition(this.property.position);
this.property.listItems = this.property.targetList.getItems(this.property.query);
this.property.clientContext.load(this.property.listItems);
this.property.clientContext.executeQueryAsync(Function.createDelegate(this, success), Function.createDelegate(this, error));
},
/*设置分页控件状态*/
pagerControlHandle:function () {
this.property.position = this.property.listItems.get_listItemCollectionPosition();
if (this.property.position == null) {
if (this.property.pageState == "next")//如果是最后一页,禁用下一页
{
if (this.property.controlActionType == "css")
$("#" + this.property.nextControlID).css("display", "none");
if (this.property.controlActionType == "attr")
$("#" + this.property.nextControlID).attr("disabled", "disabled");
}
else if (this.property.pageState == "prev") {//如果是第一页,禁用上一页
if (this.property.controlActionType == "css")
$("#" + this.property.prevControlID).css("display", "none");
if (this.property.controlActionType == "attr")
$("#" + this.property.prevControlID).attr("disabled", "disabled");
}
else {//不足一页数据,上一页下一页按钮都禁用
if (this.property.controlActionType == "css") {
$("#" + this.property.prevControlID).css("display", "none");
$("#" + this.property.nextControlID).css("display", "none");
}
if (this.property.controlActionType == "attr") {
$("#" + this.property.prevControlID).attr("disabled", "disabled");
$("#" + this.property.nextControlID).attr("disabled", "disabled");
}
}
this.property.position = this.property.lastState;
}
else {
if (this.property.pageIndex == 1) {//如果到第一页,上一页禁用
//删除下一页的禁用状态
if (this.property.controlActionType == "css") {
$("#" + this.property.prevControlID).css("display", "none");
$("#" + this.property.nextControlID).css("display", "block");
}
if (this.property.controlActionType == "attr") {
$("#" + this.property.nextControlID).removeAttr("disabled");
$("#" + this.property.prevControlID).attr("disabled", "disabled");
}
}
}
},
isEmpty:function(value){
if ($.trim(value).length != 0) {
return false;
}
return true;
}
}
经过很多次的测试,终于不再出bug。很好用的小插件。推荐各位博友。
SharePoint2013 SharePoint-Hosted 模式 分页方法的更多相关文章
- 基于华清远见STM32f051的 IIC从模式实现方法
作者:卢老师,华清远见嵌入式学院讲师. 在大多情况下,我们使用MCU控制传感器,节点以及相关从设备,但在较为复杂的系统中,有时候也会使用MCU做为从设备. 下面是关于stm32f051的从模式实现方法 ...
- Oracle、SQL Server、MySQL分页方法
测试用例:查询TEST_TABLE表中TEST_COLUMN列的第10-20条数据 1,Oracle分页方法 SELECT A.* FROM ( SELECT ROWNUM ROWNO, B.* FR ...
- 设置IE默认文本模式的方法
设置IE默认文本模式的方法 <meta http-equiv="X-UA-Compatible" content="IE=8" /> IE=5.6. ...
- 【解决】SharePoint集成模式下Reporting Service—为用户授予的权限不足,无法执行此操作。 (rsAccessDenied)
环境:Windows Server 2008 R2 SP1,SharePoint 2010 企业版,SQL Server 2008 R2 Reporting Service(SharePoint集成模 ...
- Atitit. 软件设计 模式 变量 方法 命名最佳实践 vp820 attilax总结命名表大全
Atitit. 软件设计 模式 变量 方法 命名最佳实践 vp820 attilax总结命名表大全 1. #====提升抽象层次1 2. #----使用通用单词1 3. #===使用术语..1 4. ...
- Sql Server 2012 的新分页方法分析(offset and fetch) - 转载
最近在分析 Sql Server 2012 中 offset and fetch 的新特性,发现 offset and fetch 无论语法的简洁还是功能的强大,都是相当相当不错的 其中 offset ...
- phalcon几种分页方法
phalcon几种分页方法 一: use Phalcon\Paginator\Adapter\Model as PaginatorModel; // Current page to show // I ...
- 只是一个用EF写的一个简单的分页方法而已
只是一个用EF写的一个简单的分页方法而已 慢慢的写吧.比如,第一步,先把所有数据查询出来吧. //第一步. public IQueryable<UserInfo> LoadPagesFor ...
- Java设计模式之工厂模式(简单工厂模式+工厂方法模式)
摘自http://blog.csdn.net/jason0539/article/details/23020989 在面向对象编程中, 最通常的方法是一个new操作符产生一个对象实例,new操作符就是 ...
随机推荐
- adb 启动失败的原因和修改adb端口号
在我们使用Android Studio的时候,有时候就会出现adb打开失败或者启动不了的情况. adb 启动失败的原因:有其他程序占用了adb默认启动的端口号(像我就遇到过,每次只要提前启动了酷狗音乐 ...
- SQL Where语句中AND与OR的计算次序 .
AND 用在where子句中,用来指示检索满足所有给定条件的行,而OR用在where子句中,用来指示检索匹配任一给定条件的行. Where子句中可包含任意数目的AND和OR操作符号,但是要注意在SQL ...
- decorview that was originally added here or java.lang.IllegalArgumentException: View not attached to window manager
使用Dialog的时候,没少出现下面这两个报错 12-11 17:47:49.776: E/WindowManager(11461): android.view.WindowLeaked: Activ ...
- STC12C5A60S2片内存储器介绍
STC12C5A60S2内部集成RAM 1280字节,其中 内部RAM(data):256 Byte 内部扩展RAM(xdata):1024 Byte 支持片外扩展RAM: 64kB STC12C5A ...
- 浅谈iOS中MVVM的架构设计与团队协作
说到架构设计和团队协作,这个对App的开发还是比较重要的.即使作为一个专业的搬砖者,前提是你这砖搬完放在哪?不只是Code有框架,其他的东西都是有框架的,比如桥梁等等神马的~在这儿就不往外扯了.一个好 ...
- 射频识别技术漫谈(4)——数据编码【worldsing 笔记】
前已述及,射频识别技术中的调制方法一般使用调幅(AM),也就是将有用信号调制在载波的幅度上传送出去.这里的"有用信号"指用高低电平表示的数据"0"或" ...
- js 类似php中foreach的方法
参考下面实例 <script>var arr = { 'a' : '111111', 'b' : '222222', 'c' : '333333'};for(var k ...
- WM_VSCROLL
关键点 控制滚动条在最下面 实现过程 SendMessage(form1.Memo1.Handle,WM_VSCROLL,SB_BOTTOM,0); 图 备注 相关链接 来自为知笔记(Wiz)
- iOS开发——OC篇&协议篇/NSCoder/NSCoding/NSCoping
协议篇/NSCoder/NSCoding/NSCoping 协议声明类需要实现的的方法,为不同的类提供公用方法,一个类可以有多个协议,但只能有一个父类,即单继承.它类似java中的接口. 正式协议(f ...
- G711
G.711就是语音模拟信号的一种非线性量化.细分有二种:G.711 a-lawand G.711 u-law.不同的国家和地方都会选取一种作为自己的标准. G.711a/u bitrate 是64kb ...