Created
May 12, 2013 16:11
-
-
Save beyond-code-github/5564047 to your computer and use it in GitHub Desktop.
Javascript for Linq to Querystring paging sample
This file contains 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
// 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