サーバー側の処理でデータテーブルを使用しています。
私の問題は、ページネーション メニューの [次へ] ボタンが正しく機能しないことです。
ページ番号 1 が選択されている場合、[次へ] は正常に機能します。ページ番号 2 が選択されている場合、[次へ] を押すと、テーブルがページ番号 102 にロードされます (iDisplayStart パラメータは 20 ではなく 1010 に設定されます)。
これは私の初期化コードです:
oTable = $('#solutionsTable').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"bSort": false,
"oLanguage": {
"sSearch": "Search all columns:"
},
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": '@Url.Action("AsyncGetUserData")',
"bDeferRender": true,
"aoColumns": [
//User
{ "mData": function(source, type, val){
var returnString = "<b>Name: </b>" +"<span>" + source.userName + "</span>" +
"<br/><b>Type: </b>" + "<span>" + source.roleName + "</span><br/>" +
"<b>Status: </b>" + "<span>" + source.isActive + "</span>";
return returnString;
}},
...................................
//Options
{ "mData": function(source, type, val){
var editUrl = '@Url.Action("Account", "CMS")' + '?userId=' + source.userID;
var returnString = "<a href=" + editUrl + ">Edit</a>" + " / " +
"<a href=\"#\" onclick=\"postDelete('" + source.userID +"')\">Delete</a>";
return returnString;
}}
]
}).fnSetFilteringDelay();
そして、これは私のコントローラーアクションです:
public ActionResult AsyncGetUserData(jQueryDataTableParamModel param)
{
var allUsers = CMSHelper.GetUsers(countries: User.IsInRole("Account Admin") ? CMSHelper.GetAdminCountries(User.Identity.Name).Select(c => c.Key).ToList() : null);
IEnumerable<UserModel> filteredResults = null;
string filterLowerCase = "";
string userFilter = "";
string activityFilter = "";
string contactFilter = "";
string workFilter = "";
string addressFilter = "";
if (!String.IsNullOrWhiteSpace(param.sSearch))
filterLowerCase = param.sSearch.ToLower();
if (!String.IsNullOrWhiteSpace(Request["sSearch_0"].ToString()))
userFilter = Request["sSearch_0"].ToString().ToLower();
if (!String.IsNullOrWhiteSpace(Request["sSearch_1"].ToString()))
activityFilter = Request["sSearch_1"].ToString();
if (!String.IsNullOrWhiteSpace(Request["sSearch_2"].ToString()))
contactFilter = Request["sSearch_2"].ToString().ToLower();
if (!String.IsNullOrWhiteSpace(Request["sSearch_3"].ToString()))
workFilter = Request["sSearch_3"].ToString().ToLower();
if (!String.IsNullOrWhiteSpace(Request["sSearch_4"].ToString()))
addressFilter = Request["sSearch_4"].ToString().ToLower();
if (!String.IsNullOrWhiteSpace(param.sSearch))
filteredResults = allUsers.Where(f => f.userName.ToLower().Contains(filterLowerCase)
|| f.firstName.ToLower().Contains(filterLowerCase)
|| f.lastName.ToLower().Contains(filterLowerCase)
|| (f.City == null ? "N/A" : f.City).ToLower().Contains(filterLowerCase)
|| (f.company == null ? "N/A" : f.company).ToLower().Contains(filterLowerCase)
|| f.countryName.ToLower().Contains(filterLowerCase)
|| f.email.ToLower().Contains(filterLowerCase)
|| (f.job == null ? "N/A" : f.job).ToLower().Contains(filterLowerCase)
|| f.LastLogin.ToString().Contains(filterLowerCase)
|| f.LoginsNum.ToString().Contains(filterLowerCase)
|| (f.phone == null ? "N/A" : f.phone).ToLower().Contains(filterLowerCase)
|| (f.Postcode == null ? "N/A" : f.Postcode).ToLower().Contains(param.sSearch)
|| (f.Street == null ? "N/A" : f.Street).ToLower().Contains(filterLowerCase)
|| f.type.ToLower().Contains(filterLowerCase)
|| (f.isActive == true ? "active" : "inactive").Contains(filterLowerCase)).Select(f => f);
else
filteredResults = allUsers;
if (!String.IsNullOrWhiteSpace(userFilter))
filteredResults = filteredResults.Where(f => f.userName.ToLower().Contains(userFilter)
|| f.type.ToLower().Contains(userFilter)
|| (f.isActive == true ? "active" : "inactive").Contains(userFilter));
if (!String.IsNullOrWhiteSpace(activityFilter))
filteredResults = filteredResults.Where(f => f.LoginsNum.ToString().Contains(activityFilter)
|| f.LastLogin.ToString().Contains(activityFilter));
if (!String.IsNullOrWhiteSpace(contactFilter))
filteredResults = filteredResults.Where(f => f.firstName.ToLower().Contains(contactFilter)
|| f.lastName.ToLower().Contains(contactFilter)
|| f.email.ToLower().Contains(contactFilter)
|| (string.IsNullOrEmpty(f.phone) ? "N/A" : f.phone).ToLower().Contains(contactFilter));
if (!String.IsNullOrWhiteSpace(workFilter))
filteredResults = filteredResults.Where(f => (f.company == null ? "N/A" : f.company).ToLower().Contains(workFilter)
|| (f.job == null ? "N/A" : f.job).ToLower().Contains(workFilter));
if (!String.IsNullOrWhiteSpace(addressFilter))
filteredResults = filteredResults.Where(f => f.countryName.ToLower().Contains(addressFilter)
|| (f.City == null ? "N/A" : f.City).ToLower().Contains(addressFilter)
|| (f.Street == null ? "N/A" : f.Street).ToLower().Contains(addressFilter)
|| (f.Postcode == null ? "N/A" : f.Postcode).ToLower().Contains(addressFilter));
var displayedUsers = filteredResults.Skip(param.iDisplayStart).Take(param.iDisplayLength);
var result = from u in displayedUsers
select new
{
userID = Convert.ToString(u.userId),
userName = u.userName,
roleName = u.type,
isActive = u.isActive == true ? "Active" : "Inactive",
firstName = u.firstName,
lastName = u.lastName,
email = u.email,
phone = (u.phone == null ? "N/A" : u.phone),
postcode = (u.Postcode == null ? "N/A" :u.Postcode),
street = (u.Street == null ? "N/A" : u.Street),
company = (u.company == null ? "N/A" : u.company),
job = (u.job == null ? "N/A" : u.job),
countryName = u.countryName,
city = (u.City == null ? "N/A" : u.City),
loginsNum = u.LoginsNum.ToString(),
lastLogin = u.LastLogin.ToString()
};
return Json(new
{
sEcho = int.Parse(param.sEcho),
iTotalRecords = allUsers.Count(),
iTotalDisplayRecords = filteredResults.Count(),
aaData = result
}, JsonRequestBehavior.AllowGet);
}
datatables フォーラムを検索したところ、そのようなものが見つかりました。以前にこの問題に遭遇したことがある場合、または原因が何か考えられる場合は、お知らせください。ありがとう。