Apologies for a late answer but I hope someone steps into my code when dealing with more than 100,000 in a SharePoint list. It's good to mention that I gat some of the code on the web(Can't recall the author's name to quote him). Then modified it to use JavaScript Prototypes to Load the methods once when the page is refreshed to cope performance issues.
Here you go Morten:
var HugeList = function() {
this.altWeb = _spPageContextInfo.webAbsoluteUrl + '/' || '';
this.curWebsite = window.location.protocol + '//' + window.location.host;
this.completeUrl = this.curWebsite + '/sites/thewire/' || this.altWeb;
};
HugeList.prototype.replayCenter = function(listName) {
var ItemCount = this.GetItemCount(this.completeUrl, listName);
this.createRestUrl(this.completeUrl, ItemCount, listName);
};
HugeList.prototype.GetItemCount = function(siteurl, ListName) {
var ItemCount = '';
$.ajax({
url: siteurl + "/_api/web/lists/GetByTitle('" + ListName + "')/ItemCount",
method: 'GET',
async: true,
headers: { Accept: 'application/json; odata=verbose' }
})
.done(function(data) {
ItemCount = data.d.ItemCount;
})
.fail(function(data) {
console.log(data);
});
return ItemCount;
};
HugeList.prototype.createRestUrl = function(siteurl, ItemCount, ListName) {
// prettier-ignore
var listServiceUrl = this.completeUrl+ "_api/web/lists/GetByTitle('" + ListName + "')/Items?$select=Title, BRANCH_DEPARTMENT, PHONE, COMPANY&$top=200";
//Step 3: Rest call to procerss each items of list
$.when(this.processList(listServiceUrl, ItemCount)).done(function() {});
};
HugeList.prototype.processList = function(nextUrl, ItemCount, gridID) {
gridID = gridID || 'table_id';
var dfd = new $.Deferred();
if (nextUrl == undefined) {
dfd.resolve();
return;
}
this.getJSONDataFromUrl(nextUrl).done(
function(listItems) {
var items = listItems.d.results;
var next = listItems.d.__next || '';
var indexAt = next.indexOf('_api');
var resUrl = next.slice(indexAt);
$.when(this.processList(this.completeUrl + resUrl, ItemCount)).done(
function() {
dfd.resolve();
}
);
var tableHTML = '';
var table = $('#' + gridID).DataTable();
$.each(items, function(index, obj) {
// prettier-ignore
var phonenumber = obj.PHONE ? obj.PHONE : "-";
// prettier-ignore
tableHTML +="<tr><td>" + obj.Title + "</td><td>" +obj.BRANCH_DEPARTMENT
+"</td><td>" +phonenumber +"</td><td>" +obj.COMPANY +"</td></tr>";
});
table.rows.add($(tableHTML)).draw(); //Append each list row to data tabel
}.bind(this)
); // Bind to HugeList context.
return dfd.promise();
};`
HugeList.prototype.getJSONDataFromUrl = function(endpoint) {
return jQuery.ajax({
url: endpoint,
method: 'GET',
headers: {
Accept: 'application/json; odata=verbose',
'Content-Type': 'application/json; odata=verbose'
}
});
};
var largeList = new HugeList();
largeList.replayCenter('EmployeesList');