我有一个mvc web应用程序,其中包含来自datatables的jquery代码并且可以进行jeditable。在我的一个观点中,我有一个包含项目,用户和部门的表。每个项目都有一个负责任的人。现在我想让管理员可以通过在服务器端创建的下拉列表来更改可信任的人。为了确保他不破坏任何部门结构,他应该只能从项目所在部门中选择成员。要解决这个问题,我必须根据department部分中的条目加载下拉列表。 据我了解数据表,如果页面被创建,下拉列表将被加载,因此我不可能根据部门行更改它。有谁跟我说我怎么能解决我的问题?
这是html代码:
<script>
$(document).ready(function () {
var oTable = $('#ProjectTable').dataTable({
"bServerSide": true,
"sAjaxSource": "@Url.Action("ProjectTableHandler", "ManageDepartment")",
"aLengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
"bProcessing": true,
"bPaginate": true,
"sPaginationType": "full_numbers",
"sDom": 'ftrlp',
"bInfo": false,
"oLanguage": {
"sSearch": "Search in your departments for projects: ",
"oPaginate":
{
"sNext": 'next',
"sLast": '>>',
"sFirst": '<<',
"sPrevious": 'prev'
}
},
"bDeferRender": true,
"aoColumns": [
{ "sName": "ID", "bSearchable": false, "bSortable": false, "bVisible": false },
{ "sName": "Id" },
{ "sName": "Name" },
{ "sName": "RespUser" },
{ "sName": "Department" }
]
});
oTable.columnFilter({ sPlaceHolder: "head:after", "aoColumns": [null, null, null, null] });
oTable.makeEditable({
"aoColumns": [null,
{ onblur: 'submit' },
null,
null],
sUpdateURL: "@Url.Action("UpdateProject", "ManageDepartment")",
});
});
</script>
<hgroup>
<h1>Manage the projects of the own departments</h1>
</hgroup>
<fieldset>
<legend id="ManageProjectsHeadline">Projects </legend>
<table id="ProjectTable" class="display">
<thead>
<tr>
<th>@Html.Label("ID")</th>
<th>@Html.Label("Id")</th>
<th>@Html.Label("Name") </th>
<th>@Html.Label("RespUser", "Responsible user") </th>
<th>@Html.Label("Department", "Department")</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</tfoot>
</table>
<div class="toolbar">
<input type="button" class="AskButton" id="Ask" value="?" />
</div>
</fieldset>
和表处理程序:
[HandleError(ExceptionType = typeof(BusinessObjectNotRetrievableByIdException), View = "BusinessObjectNotFound")]
[HandleError]
public ActionResult ProjectTableHandler(JQueryDataTableParamModel param)
{
List<Project> AllProjects = ProjectManagement.GetProjectsOfDepartmentList(UserManagement.GetAllOrganisationUnitsFromHoDOrDA(UserManagement.GetSingle(Session.Current.UserComparison.GetUserId()))).ToList().ConvertAll(i => (Project)i);
var isIDSearchable = Convert.ToBoolean(Request["bSearchable_1"]);
var isNameSearchable = Convert.ToBoolean(Request["bSearchable_2"]);
var isPISearchable = Convert.ToBoolean(Request["bSearchable_3"]);
var isDepartmentSearchable = Convert.ToBoolean(Request["bSearchable_4"]);
IEnumerable<Project> filteredProjects;
if (!String.IsNullOrEmpty(param.sSearch)) filteredProjects = AllProjects.Where(a => isNameSearchable && a.Name.ToUpper().Contains(param.sSearch.ToUpper()) || isPISearchable && a.SecureEntity.User != null && (a.SecureEntity.User.LastName.ToUpper().Contains(param.sSearch.ToUpper()) || isDepartmentSearchable && a.SecureEntity.OrganisationUnit != null && a.SecureEntity.OrganisationUnit.Name.ToUpper().Contains(param.sSearch.ToUpper()));
else filteredProjects = AllProjects;
filteredProjects = filteredProjects.Where(a => (isVisibilitySearchable && vis == "" || ((a.SecureEntity.Visibility >= 0 && a.SecureEntity.Visibility <= 3) && a.SecureEntity.Visibility == Convert.ToByte(vis)))).Distinct();
var isIDSortable = Convert.ToBoolean(Request["bSortable_1"]);
var isNameSortable = Convert.ToBoolean(Request["bSortable_2"]);
var isPISortable = Convert.ToBoolean(Request["bSortable_3"]);
var isDepartmentSortable = Convert.ToBoolean(Request["bSortable_4"]);
var sortColumnIndex = Convert.ToInt32(Request["iSortCol_0"]);
Func<Project, string> orderingFunction = (c => sortColumnIndex == 1 && isIDSortable ? Convert.ToString(c.Id) : sortColumnIndex == 2 && isNameSortable ? c.Name : sortColumnIndex == 4 && isPISortable ? c.SecureEntity.User.LastName : sortColumnIndex == 3 && isDepartmentSortable ? c.SecureEntity.OrganisationUnit.Name : "");
var sortDirection = Request["sSortDir_0"];
if (sortDirection == "asc") filteredProjects = filteredProjects.OrderBy(orderingFunction);
else filteredProjects = filteredProjects.OrderByDescending(orderingFunction);
if (param.iDisplayLength != -1) filteredProjects = filteredProjects.Skip(param.iDisplayStart).Take(param.iDisplayLength);
var ProjectStringList = new List<string[]>();
foreach (var Project in filteredProjects)
{
var url = Url.Action("ProjectDetails", "Projects", new { id = Project.Id });
ProjectStringList.Add(new string[] { Convert.ToString(Project.Id), "<a href='" + url + "'>" + Convert.ToString(Project.Id) + "<a>", Project.Name, "" + Project.SecureEntity.User.FirstName + " " + Project.SecureEntity.User.LastName, Project.SecureEntity.OrganisationUnit.Name });
}
return Json(new { sEcho = param.sEcho, iTotalRecords = AllProjects.Count(), iTotalDisplayRecords = filteredProjects.Count(), aaData = ProjectStringList }, JsonRequestBehavior.AllowGet);
}