Skip to content

Instantly share code, notes, and snippets.

@beyond-code-github
Created May 12, 2013 16:11
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/5564047 to your computer and use it in GitHub Desktop.
Save beyond-code-github/5564047 to your computer and use it in GitHub Desktop.
Javascript for Linq to Querystring paging sample
// Define the viewmodel
var model = {};
model.records = ko.observableArray();
model.count = ko.observable(0);
model.currentPage = ko.observable(1);
model.pageSize = ko.observable(5);
model.pages = ko.computed(function () {
var pages = [];
if (model.count() > 0) {
var pageCount = Math.ceil(model.count() / model.pageSize());
for (var i = 0; i < pageCount; i++) {
pages.push(i + 1);
}
}
return pages;
});
// Button click function
model.getData = function () {
$.get("/api/values", function (data) {
model.count(data.length);
model.records(data);
});
};
// Get data and bind viewmodel on page load
$(document).ready(function () {
model.getData();
ko.applyBindings(model);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment