dataTable.net 服务器端处理:似乎没有刷新
对于我和我的同事正在开发的网站,我们使用了 www.dataTables.net 中的 dataTable 格式,并且由于表的增长量,我们必须使用服务器端处理。这是视图:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$('#adminUnassignedTable').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "/Admin/UpdateUnassignedReviewer",
"sPaginationType": "full_numbers"
});
});
</script>
<h2>Unassigned IPBs</h2>
<%
using (Html.BeginForm("Assign","Admin",FormMethod.Post))
{
Html.RenderPartial("AssignmentControls", "Reviewer");
%>
<table cellpadding="0" cellspacing="0" border="0" class="display" id="adminUnassignedTable">
<thead><tr>
<th>IPB Number</th>
<th>IPB Pub Date</th>
<th>Change Number</th>
<th>Change Date</th>
<th>Total # of Parts</th>
<th>Total # of Report Parts</th>
<th>ALC</th>
<th>Date Loaded</th>
<th>Priority</th>
<th>Update</th>
</tr></thread>
<tbody><tr><td colspan="12" class="dataTable_empty">Loading Data From Server</td></tr></tbody>
</table>
<%
}
%>
这是 AdminController.cs 中的 sAjaxSource 函数:
public void UpdateUnassignedReviewer()
{
int[] nArrayStatus = { (int)PTA.Helpers.Constants.State.Queue }
int nTotalRecordCount = 0;
string strEcho = "";
_DisplayRecords = PTA.Helpers.Utility.BeginServerSideProcessing(HttpContext.Request.QueryString, nArrayStates, (int)PTA.Helpers.Constants.Location.Reviewer, ref nTotalRecordCount, ref strEcho);
string strOutput = "";
if (_DisplayRecords.Count() <= 0)
{
PTA.Helpers.Utility.WriteBlankRecord(ref strOutput, strEcho, 12);
}
else
{
strOutput += "{\"sEcho\":" + strEcho + ", ";
strOutput += "\"iTotalRecords\": " + nTotalRecordCount.ToString() + ", ";
strOutput += "\"iTotalDisplayRecords\": " + nTotalRecordCount.ToString() + ", ";
strOutput += "\"aaData\": [";
int nCounter = 0;
foreach (IPB ipb in _DisplayRecords)
{
strOutput += "[ "
strOutput += "\"";
strOutput += PTA.Helpers.Utility.CreateDetailsLinkHTML(ipb.ID.ToString(), ipb.IPBName) + "\",";
strOutput += "\"" + ipb.PubDate + "\",";
strOutput += "\"" + ipb.Change + "\",";
strOutput += "\"" + ipb.ChangeDate + "\",";
strOutput += "\"" + ipb.TotalParts + "\",";
strOutput += "\"" + ipb.TotalPartsReport + "\",";
strOutput += "\"" + ipb.ALC + "\",";
strOutput += "\"" + ipb.DateAdded + "\",";
strOutput += "\"" + ipb.Priority + "\",";
strOutput += "\"" + PTA.Helpers.Utility.CreateCheckBoxHTML(ipb.ID.ToString(), nCounter++);
strOutput += "\"";
strOutput += "]";
if(ipb != _DisplayRecords.Last())
{
strOutput += ", ";
}
}
}
strOutput += "]}";
Response.Write(strOutput);
}
这是分配函数
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Assign(string PriorityDropDown, string UserDropDown, string ActionDropDown)
{
ResetTempData(ref statusID, ref locationID, ref area);
int ipb_id = 0,
action = -1;
action = Request.Form["ActionDropDown"].ToString() == null || Request.Form["ActionDropDown"].ToString() == "" ? -1 : Convert.ToInt32(Request.Form["ActionDropDown"]);
string strUser = "",
strPriority = "";
strUser = Request.Form["UserDropDown"];
strPriority = Request.Form["PriorityDropDown"];
string[] strTemp = Request.Form.AllKeys;
foreach(string str in strTemp)
{
if(str.Contains("AssignCheck"))
{
ipb_id = Convert.ToInt32(Request.Form[str]);
if(action > -1 || (strUser != null || strUser != "") || (strPriority != null || strPriority != ""))
{
switch (action)
{
case -1:
Update(ipb_id, strPriority, strUser);
break;
case 1:
case 2:
case 5:
case 8:
Action(ipb_id, action);
break;
default: break;
}
}
}
}
return RedirectToAction("AdminView");
}
这是 AdminView 函数
public ActionResult(int? statusID, int? locationID)
{
if (!System.Web.HttpContext.Current.User.IsInRole("Admin"))
{
return RedirectToAction("Index", "Home");
}
PTA.Modesl.DataFactory factory = new DataFactory();
if(statusID == null)
{
statusID = (int)PTA.Helpers.Constants.State.Queue;
ViewData["status"] = statusID;
}
if(locationID == null)
{
locationID = (int)PTA.Helpers.Constants.Location.Reviewer;
ViewData["location"] = locationID;
}
TempData["pageStatus"] = statusID;
TempData["pageLocation"] = locationID;
TempData["Area"] = Request.QueryString["Area"]?? "Unassigned";
return View();
}
另外,请注意,我的开发计算机与我的网络计算机不同。所以我不能复制和粘贴,我也不能使用拇指驱动器。因此,我必须手动输入所有内容。因此,如果您发现一些拼写错误,请询问我,我会告诉您是否正确。另外,您可能会要求查看两个操作,我只是没有输入它们,因为输入其他所有内容需要很长时间。行动和分配。如果您想/需要见他们,请告诉我。谢谢。
For the site my coworkers and I are working on, we used the dataTable format from www.dataTables.net and we have to use Server-Side processing because of how much the tables grow. Here's the view:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$('#adminUnassignedTable').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "/Admin/UpdateUnassignedReviewer",
"sPaginationType": "full_numbers"
});
});
</script>
<h2>Unassigned IPBs</h2>
<%
using (Html.BeginForm("Assign","Admin",FormMethod.Post))
{
Html.RenderPartial("AssignmentControls", "Reviewer");
%>
<table cellpadding="0" cellspacing="0" border="0" class="display" id="adminUnassignedTable">
<thead><tr>
<th>IPB Number</th>
<th>IPB Pub Date</th>
<th>Change Number</th>
<th>Change Date</th>
<th>Total # of Parts</th>
<th>Total # of Report Parts</th>
<th>ALC</th>
<th>Date Loaded</th>
<th>Priority</th>
<th>Update</th>
</tr></thread>
<tbody><tr><td colspan="12" class="dataTable_empty">Loading Data From Server</td></tr></tbody>
</table>
<%
}
%>
Here's the sAjaxSource function in the AdminController.cs:
public void UpdateUnassignedReviewer()
{
int[] nArrayStatus = { (int)PTA.Helpers.Constants.State.Queue }
int nTotalRecordCount = 0;
string strEcho = "";
_DisplayRecords = PTA.Helpers.Utility.BeginServerSideProcessing(HttpContext.Request.QueryString, nArrayStates, (int)PTA.Helpers.Constants.Location.Reviewer, ref nTotalRecordCount, ref strEcho);
string strOutput = "";
if (_DisplayRecords.Count() <= 0)
{
PTA.Helpers.Utility.WriteBlankRecord(ref strOutput, strEcho, 12);
}
else
{
strOutput += "{\"sEcho\":" + strEcho + ", ";
strOutput += "\"iTotalRecords\": " + nTotalRecordCount.ToString() + ", ";
strOutput += "\"iTotalDisplayRecords\": " + nTotalRecordCount.ToString() + ", ";
strOutput += "\"aaData\": [";
int nCounter = 0;
foreach (IPB ipb in _DisplayRecords)
{
strOutput += "[ "
strOutput += "\"";
strOutput += PTA.Helpers.Utility.CreateDetailsLinkHTML(ipb.ID.ToString(), ipb.IPBName) + "\",";
strOutput += "\"" + ipb.PubDate + "\",";
strOutput += "\"" + ipb.Change + "\",";
strOutput += "\"" + ipb.ChangeDate + "\",";
strOutput += "\"" + ipb.TotalParts + "\",";
strOutput += "\"" + ipb.TotalPartsReport + "\",";
strOutput += "\"" + ipb.ALC + "\",";
strOutput += "\"" + ipb.DateAdded + "\",";
strOutput += "\"" + ipb.Priority + "\",";
strOutput += "\"" + PTA.Helpers.Utility.CreateCheckBoxHTML(ipb.ID.ToString(), nCounter++);
strOutput += "\"";
strOutput += "]";
if(ipb != _DisplayRecords.Last())
{
strOutput += ", ";
}
}
}
strOutput += "]}";
Response.Write(strOutput);
}
Here's the Assign function
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Assign(string PriorityDropDown, string UserDropDown, string ActionDropDown)
{
ResetTempData(ref statusID, ref locationID, ref area);
int ipb_id = 0,
action = -1;
action = Request.Form["ActionDropDown"].ToString() == null || Request.Form["ActionDropDown"].ToString() == "" ? -1 : Convert.ToInt32(Request.Form["ActionDropDown"]);
string strUser = "",
strPriority = "";
strUser = Request.Form["UserDropDown"];
strPriority = Request.Form["PriorityDropDown"];
string[] strTemp = Request.Form.AllKeys;
foreach(string str in strTemp)
{
if(str.Contains("AssignCheck"))
{
ipb_id = Convert.ToInt32(Request.Form[str]);
if(action > -1 || (strUser != null || strUser != "") || (strPriority != null || strPriority != ""))
{
switch (action)
{
case -1:
Update(ipb_id, strPriority, strUser);
break;
case 1:
case 2:
case 5:
case 8:
Action(ipb_id, action);
break;
default: break;
}
}
}
}
return RedirectToAction("AdminView");
}
Here's the AdminView function
public ActionResult(int? statusID, int? locationID)
{
if (!System.Web.HttpContext.Current.User.IsInRole("Admin"))
{
return RedirectToAction("Index", "Home");
}
PTA.Modesl.DataFactory factory = new DataFactory();
if(statusID == null)
{
statusID = (int)PTA.Helpers.Constants.State.Queue;
ViewData["status"] = statusID;
}
if(locationID == null)
{
locationID = (int)PTA.Helpers.Constants.Location.Reviewer;
ViewData["location"] = locationID;
}
TempData["pageStatus"] = statusID;
TempData["pageLocation"] = locationID;
TempData["Area"] = Request.QueryString["Area"]?? "Unassigned";
return View();
}
Also, as a note, my dev machine is not the same as my network machine. So I can't copy and paste, I also can't use thumb drives. Therefore, I have to manually type everything. So if you see some typos, just ask me and I'll let you know if it's correct. Also, there are two actions you may ask to see, I just didn't type them just because of how long it took to type everything else. Action and Assign. If you want/need to see them, let me know. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
哈哈。答案是使用最新版本。当我应该使用 1.7.0 时,我却使用了 1.6.7。现在效果很好。
lol. The answer is use the newest version. I was using 1.6.7 when I should have been using 1.7.0. It now works fine.