-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuglypagingReadSPListData.js
More file actions
66 lines (49 loc) · 1.94 KB
/
uglypagingReadSPListData.js
File metadata and controls
66 lines (49 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
function GetPageData(listName, itemsPerPage, pageToLoad, selector) {
siteURL = _spPageContextInfo.webAbsoluteUrl;
console.log("from top nav - " + siteURL);
var toskip = (pageToLoad * itemsPerPage) - itemsPerPage;
var endpointUrl = siteURL + "/_api/web/lists/getbytitle('" + listName + "')/items?$skiptoken=" + encodeURIComponent('Paged=TRUE&p_SortBehavior=0&p_ID=' + (toskip) + '&$top=' + itemsPerPage);
console.log(endpointUrl);
$.ajax({
url: endpointUrl,
headers: {
Accept: "application/json;odata=verbose"
},
async: false,
success: function (data) {
console.log(data)
$(selector).empty();
data.d.results.forEach(element => {
$(selector).append(element.Title);
});
},
eror: function (data) {
console.log("An error occurred. Please try again.");
}
});
}
function initPager(config) {
var length = Math.round(config.allItems / config.itemsPerPage);
for (let index = 0; index < length; index++) {
var displayPage = index + 1;
$(config.selector).append(`<li onClick="GetPageData('${config.listName}',${config.itemsPerPage},${displayPage},'${config.contSelector}')">${displayPage}</li>`);
}
}
$(function () {
var listName = 'Directorio';
siteURL = _spPageContextInfo.webAbsoluteUrl;
console.log("from top nav - " + siteURL);
var apiPath = siteURL + `/_api/web/lists/GetByTitle('${listName}')/items`;
//get total
$.ajax({
url: siteURL + `/_api/web/lists/GetByTitle('${listName}')?$Select=ItemCount,Title`,
headers: {
Accept: "application/json;odata=verbose"
},
async: false,
success: function (data) {
// console.log(data);
initPager({ selector: "#pager", allItems: data.d.ItemCount, itemsPerPage: 2, listName: listName, contSelector: '.cont' });
}
});
})