我有一个剑道下拉列表它可以工作,但我需要让它成为一个没有按钮的实时下拉列表......每当我在下拉列表中选择一个项目时,它会自动更新我的网格内的内容或我的网格上的查询基于选择的下拉列表。
这是我的代码:
@using (Html.BeginForm())
{
<input type="hidden" id="hiddenUser" name="hiddenUser" value="@userId" />
<p>
<input id="ddlWorker" name="ddlWorker" style="width: 250px;" value="@ddlWorker" />
<input type="submit" value="Filter Workers by Position" class="styledButton" />
</p>
}
JS:
var userId = $("#hiddenUser").val();
$("#ddlWorker").kendoDropDownList({
dataTextField: "JobCode",
dataValueField: "ID",
autoBind: false,
optionLabel: {
JobCode: "--- Please Select Position ---",
ID: ""
},
// define custom template
template: '<h5>${ data.JobCode }</h5>',
dataSource: {
transport: {
read: {
url: '/Worker/LoadWorkerDropdownList?userId=' + userId,
dataType: "json",
type: "POST"
}
}
}
});
var dropdownlist = $("#ddlWorker").data("kendoDropDownList");
dropdownlist.list.width(250);
我的网格控制器
public JsonResult LoadWorkerList( string search, int? positionSelected, int? statusValue)
{
// check if search string has value
// retrieve list of workers filtered by search criteria
var list = (from a in db.Workers
where a.LogicalDelete == false
select a).ToList();
List<WorkerInfo> wlist = new List<WorkerInfo>();
foreach (var row in list)
{
WorkerInfo ci = new WorkerInfo
{
ID = row.ID,
FirstName = row.FirstName,
LastName = row.LastName,
Name = row.FirstName + " " + row.LastName,
LastFName = row.LastName + " " + row.FirstName,
PositionSelected = positionSelected,
LogicalDelete = row.LogicalDelete
};
wlist.Add(ci);
}
if (positionSelected.HasValue)
{
var workerIdList = new List<Int32>();
var filterList = (from a in db.Client_Worker_Position
where a.LogicalDelete == false && positionSelected == a.ClientCustomerPositionID
select a).ToList();
var listSelect = (from a in db.Worker_Availability
where a.LogicalDelete == false
select a).ToList();
foreach (var row in listSelect)
{
var shiftList = (from a in db.Client_Customer_Position_Shift
where a.LogicalDelete == false && positionSelected == a.Client_Customer_PositionID
select a).ToList();
foreach (var positionShift in shiftList)
{
if (positionShift.Day_LookID == row.AvailableDay_LookID || positionShift.Day_LookID == 76 || row.AvailableDay_LookID == 76)
{
if (((positionShift.StartTime == "Anytime" && positionShift.EndTime == "Anytime") || (row.StartTime == "Anytime" && row.EndTime == "Anytime")) ||
(row.StartTime == "Anytime" || row.EndTime == "Anytime") || (positionShift.StartTime == "Anytime" || positionShift.EndTime == "Anytime"))
{
workerIdList.Add(row.ID);
}
else
{
DateTime posStartTime = Convert.ToDateTime(positionShift.StartTime);
DateTime availStartTime = Convert.ToDateTime(row.StartTime);
DateTime posEndTime = Convert.ToDateTime(positionShift.EndTime);
DateTime availEndTime = Convert.ToDateTime(row.EndTime);
if ((positionShift.StartTime == row.StartTime &&
positionShift.EndTime == row.EndTime) || (positionShift.StartTime == row.StartTime ||
positionShift.EndTime == row.EndTime)
|| (posStartTime < availStartTime && posEndTime > availEndTime))
{
workerIdList.Add(row.ID);
}
}
}
}
}
var toBeList = (from a in listSelect
where a.LogicalDelete == false
select a).ToList();
var setToList = toBeList.Select(x => x.ID).Except(filterList.Select(y => y.WorkerAvailabilityId)).ToList();
var selectedPosition = (from a in listSelect
join b in db.Workers
on a.Worker_ID equals b.ID
join c in db.Client_Customer_Position
on positionSelected equals c.ID
where workerIdList.Contains(a.ID) && a.LogicalDelete == false && b.LogicalDelete == false
&& c.LogicalDelete == false && setToList.Contains(a.ID)
select new WorkerInfo()
{
ID = b.ID,
WorkerAvailID = a.ID,
FirstName = b.FirstName,
PositionSelected = positionSelected,
LastName = b.LastName
}).ToList();
var distinctList = selectedPosition.GroupBy(x => x.ID)
.Select(g => g.First())
.ToList();
wlist = distinctList.ToList();
}
if (!search.Equals("Search Worker"))
{
var wolist = (from a in wlist
where a.FirstName.ToLower().Contains(search.ToLower()) ||
a.LastName.ToLower().Equals(search.ToLower()) ||
a.Name.ToLower().Equals(search.ToLower()) ||
a.LastFName.ToLower().Equals(search.ToLower())
select a).ToList();
wlist = wolist;
}
else
{
var wolist = (from a in wlist
where a.LogicalDelete == false
select a).ToList();
wlist = wolist;
}
ViewBag.positionSelected = positionSelected;
return Json(wlist.ToList().OrderBy(p => p.FirstName.ToLower()), JsonRequestBehavior.AllowGet);
}
感谢:D