Skip to content

Instantly share code, notes, and snippets.

@beyond-code-github
Created June 9, 2013 11:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beyond-code-github/e3c978314651bd400e2c to your computer and use it in GitHub Desktop.
Save beyond-code-github/e3c978314651bd400e2c to your computer and use it in GitHub Desktop.
Final version of the getData function in Getting Started with Linq to Querystring part 2
model.getData = function() {
var top = "$top=" + model.pageSize();
var skip = "$skip=" + model.pageSize() * (model.currentPage() - 1);
var inlinecount = "$inlinecount=allpages";
var filter = model.FilterModel ? model.FilterModel.getODataFilter() : "";
var oDataOptions = [top, skip, inlinecount];
if (filter) { oDataOptions.splice(0, 0, filter); }
$.get("/api/values?" + oDataOptions.join("&"), function(data) {
model.count(data.Count);
model.records(data.Results);
model.headings([]);
if (data.Results && data.Results.length > 0) {
for (prop in data.Results[0]) {
if (data.Results[0].hasOwnProperty(prop)) {
model.headings.push(prop);
}
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment