Instantly share code, notes, and snippets.
Created
March 28, 2016 18:26
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
Save peder/2af510177e0174ed72ed to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en" manifest="/app.manifest" ng-app> | |
<head> | |
<meta charset="utf-8"> | |
<title>SharePoint Search With Infinite Scroll</title> | |
<link rel="stylesheet" href="assets/css/app.css"> | |
<script type="text/javascript" src="assets/js/app.js"></script> | |
<script type="text/javascript"> | |
var sharePointUrl = "http://someSharePointSite/"; | |
var sharePointContextInfoUrl = sharePointUrl + "_api/contextinfo"; | |
var sharePointSearchUrl = sharePointUrl + _api/search/postquery; | |
var dataSource = new DevExpress.data.DataSource({ | |
load: function (loadOptions) | |
{ | |
var d = new $.Deferred(); | |
var params = {}; | |
//Getting filter options | |
if (loadOptions.filter) | |
{ | |
params.filter = JSON.stringify(loadOptions.filter); | |
} | |
//Getting sort options | |
if (loadOptions.sort) | |
{ | |
params.sort = JSON.stringify(loadOptions.sort); | |
} | |
//skip and take are used for paging | |
params.Querytext = $("#searchTerm").val(); | |
if (params.Querytext == "") | |
params.Querytext = "*"; | |
params.RowsPerPage = loadOptions.take; | |
params.RowLimit = loadOptions.take; | |
params.StartRow = loadOptions.skip; | |
//If the select expression is specified | |
if (loadOptions.select) | |
{ | |
params.select = JSON.stringify(loadOptions.select); | |
} | |
//If a user typed something in dxAutocomplete, dxSelectBox or dxLookup | |
if (loadOptions.searchValue) | |
{ | |
params.searchValue = loadOptions.searchValue; | |
params.searchOperation = loadOptions.searchOperation; | |
params.searchExpr = loadOptions.searchExpr; | |
} | |
params.ClientType = "custom", | |
params.SelectProperties = | |
{ | |
results: [ | |
"Title", | |
"Author" | |
] | |
}; | |
params.Properties = { results: [] }; | |
$.ajax(sharePointContextSearchUrl, | |
{ | |
dataType: "json", | |
jsonp: false, | |
method: "POST", | |
data: JSON.stringify({ request: params }), | |
contentType: "application/json;odata=verbose", | |
headers: | |
{ | |
"X-RequestDigest": formDigestValue, | |
"Accept": "application/json; odata=verbose" | |
} | |
}).done(function (data) | |
{ | |
var displayRows = []; | |
for(var responseRowKey in data.d.postquery.PrimaryQueryResult.RelevantResults.Table.Rows.results) | |
{ | |
var responseRow = data.d.postquery.PrimaryQueryResult.RelevantResults.Table.Rows.results[responseRowKey]; | |
var displayRow = {}; | |
for(var columnKey in responseRow.Cells.results) | |
{ | |
var column = responseRow.Cells.results[columnKey]; | |
if (column.Key == "Title" || column.Key == "Author") | |
{ | |
displayRow[column.Key] = column.Value; | |
} | |
} | |
displayRows[displayRows.length] = displayRow; | |
} | |
d.resolve(displayRows); | |
}); | |
return d.promise(); | |
} | |
}); | |
$.ajax(sharePointContextInfoUrl, | |
{ | |
dataType: "xml", | |
jsonp: false, | |
method: "POST" | |
}).done(function (data) | |
{ | |
formDigestValue = $(data).find("FormDigestValue").text(); | |
$(document).ready(function () | |
{ | |
$("#gridContainer").dxDataGrid({ | |
dataSource: dataSource, | |
customizeColumns: function (columns) | |
{ | |
}, | |
loadPanel: { | |
enabled: false | |
}, | |
scrolling: { | |
mode: 'infinite', | |
preloadEnabled: true | |
}, | |
paging: | |
{ | |
enabled: true, | |
pageSize: 60 | |
} | |
}); | |
$("#submitButton").click(function () | |
{ | |
$("#gridContainer").dxDataGrid({ | |
dataSource: dataSource, | |
customizeColumns: function (columns) | |
{ | |
}, | |
loadPanel: { | |
enabled: false | |
}, | |
scrolling: { | |
mode: 'infinite', | |
preloadEnabled: true | |
}, | |
paging: | |
{ | |
enabled: true, | |
pageSize: 60 | |
} | |
}); | |
return false; | |
}); | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<nav class="navbar navbar-default navbar-fixed-top navbar-header"> | |
<div class="container-fluid"> | |
<div class="navbar-header"> | |
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> | |
<span class="sr-only">Toggle navigation</span> | |
<span class="icon-bar"></span> | |
<span class="icon-bar"></span> | |
<span class="icon-bar"></span> | |
</button> | |
<a class="navbar-brand" href="/">SharePoint Search With Infinite Scroll</a> | |
</div> | |
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> | |
<form class="navbar-form navbar-left" role="search"> | |
<div class="form-group"> | |
<input id="searchTerm" type="text" value="" class="form-control" placeholder="Search"> | |
</div> | |
<button id="submitButton" type="submit" class="btn btn-default">Submit</button> | |
</form> | |
<ul class="nav navbar-nav navbar-left"> | |
<li><a id="advancedSearchButton" href="#">Advanced <span class="glyphicon glyphicon-cog" aria-hidden="true"></span></a></li> | |
<li><a id="virtualFoldersButton" href="#">Virtual Folders <span class="glyphicon glyphicon-folder-open" aria-hidden="true"></span></a></li> | |
<li><a href="#">Favorites <span class="glyphicon glyphicon-heart-empty" aria-hidden="true"></span></a></li> | |
</ul> | |
<ul class="nav navbar-nav navbar-right"> | |
<li><a href="#">Help</a></li> | |
</ul> | |
</div> | |
</div> | |
</nav> | |
<div id="gridContainer"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment