これは、私がやった方法です
初めてのロード:ページ番号をクリックオン
var pageSize = 100; // See, this is my default page size. You can change it.
$.ajax({
url: "http://localhost:66252/Home/Getoptions",
data:{ skip: 0, take:100 },
success: function(result) {
var total = result.length;
if (total > pageSize) { // pageSize is 100, we declared on top
var pageTotal = Math.ceil(total/pageSize);
var j;
for (var i = 0; i < pageTotal; i++)
{
j = i + 1;
//Here I'm creating li for all the pages. You can create any number of li then create a button called Next. Pass the value in Next button.
var pages = '<li class="_li"><a id="page_' + j + '" class="pageNumber" style="margin-left:0px;" href="javascript:;">' + (i + 1) + '</a></li>';
$('#_ul').append(pages); //This is my id of Ul from HTML
}
}
});
:
$(document).on("click", ".pageNumber", function() {
var value = $(this).attr('id').split('_')[1];
var skip = value == 1 ? 0 : (value * pageSize) - pageSize;
//Then call once again your ajax method here by passing skip value
$.ajax({
url: "http://localhost:66252/Home/Getoptions",
data:{ skip: skip, take:100 },
success: function(result) {
var total = result.length;
if (total > pageSize) {
var pageTotal = Math.ceil(total/pageSize);
var j;
for (var i = 0; i < pageTotal; i++)
{
j = i + 1;
//Here I'm creating li for all the pages. You can create any number of li then create a button called Next. Pass the value in Next button.
var pages = '<li class="_li"><a id="page_' + j + '"
class="pageNumber" style="margin-left:0px;"
href="javascript:;">' + (i + 1) + '</a></li>';
$('#_ul').append(pages); //This is my id of Ul from HTML
}
}
});
});
その後、あなたAction Method
で、あなた一歩踏み出すことができます電子の例えばクエリ文字列の値は、
string _skip = Request.QueryString["skip"];
string _take = Request.QueryString["take"];
次にあなたがスキップと
、例えば、あなたのLinq
またはEntity Framework
クエリで
var result =
myContext.GetData.Skip(int.Parse(_skip)).Take(int.Parse(_take)).ToList();
return json(result,jsonRequestBehaviour.AllowGet);
を方法を取るノートを追加することができます。必要に応じてCSSまたはHTMLを変更してください。たとえば、あなたのUIの、BG色、またはLiの色をクリック、または無効に李を有効にするなどなど
は、それはあなたがサーバー上でページングを行う必要があります:)
お役に立てば幸いです。 JSはこの問題とは無関係です。 '$()。ready'はdocument.readyイベントハンドラを付加する有効な方法ではないことにも注意してください。 '$(document).ready(fn)'または '$(fn)'を使用してください –
あなたのデータベースから100を得るだけです。ページ単位で実装し、レコードを取得します。 –
@RoryMcCrossanこれはJqueryの公式ドキュメント –