1
我有KendoUI網格在MVC4應用,如下所示:選擇的DataItem在劍道UI網格
@(Html.Kendo().Grid<ProjectSystem.Web.Models.ProjectModel>()
.Name("Grid")
.Editable(editable =>
{
if(User.IsInRole(Constants.Admin))
{
editable.Mode(GridEditMode.InCell);
}
else
{
editable.Enabled(false);
}
})
.Sortable(sortable => sortable.AllowUnsort(false))
.Navigatable()
.ToolBar(toolbar =>
{
if (User.IsInRole(Constants.Admin))
{
toolbar.Create();
toolbar.Save();
}
})
.Selectable(s => s.Mode(GridSelectionMode.Single).Type(GridSelectionType.Row))
.Columns(columns =>
{
columns.Bound(p => p.ProjectId);
columns.Bound(p => p.Name);
columns.Bound(p => p.Address);
columns.Bound(p => p.Postcode);
columns.Bound(p => p.Contact);
columns.Bound(p => p.Files);
columns.Bound(p => p.Link).ClientTemplate("<a href='#=Link#' target='_blank'>#=Files!=null && Files.length > 0 ? 'Dropbox' : '' #</a>");
columns.Bound(p => p.ProjectStatus);
columns.Bound(p => p.Active).ClientTemplate("<input type='checkbox' class='chkboxActive' #= Active ? checked='checked' : '' # ></input>");
columns.Bound(p => p.Unused).ClientTemplate("<input type='checkbox' class='chkboxUnused' #= Unused ? checked='checked' : '' # ></input>");
columns.Bound(p => p.IsSMS).ClientTemplate("<input type='checkbox' class='chkboxIsSMS' #= IsSMS ? checked='checked' : '' # ></input>");
columns.Bound(p => p.MaterialLink).Title("").ClientTemplate("<a href='/Material/index?projectId=#=ProjectId#'>#=GetText()#</a>");
})
.DataSource(dataSource => dataSource.Ajax()
.Model(model => model.Id(p => p.ProjectId))
.Batch(true)
.Events(events => events.Error("error"))
.Events(events => events.RequestEnd("onRequestEnd"))
.Create(create => create.Action("ProjectCreate", "Project"))
.Update(update => update.Action("ProjectUpdate", "Project"))
.Read(read => read.Action("ProjectRead", "Project").Data("ExtraData"))
)
)
的ProjectStatus列是一個枚舉,其具有UIHint稱爲StatusColumn;既shwon這裏:
枚舉:
public enum ProjectStatus
{
Open = 1,
Closed = 2
}
視圖模型:
[UIHint("StatusColumn")]
[Display(Name = "Status")]
public ProjectStatus ProjectStatus { get; set; }
的UIHint(部分圖):
@(Html.Kendo().DropDownList().Name("ProjectStatus")
.BindTo(new List<DropDownListItem>
{
new DropDownListItem{Text = "", Value = "0"},
new DropDownListItem{Text = "Open", Value = "1"},
new DropDownListItem{Text = "Closed", Value = "2"}
}
).Events(e => e.Select("saveProjectStatus")))
* 的問題:*
我其實想獲得專案編號值(在上面顯示網格列),當saveProjectStatus事件在上圖所示的下拉UI提示解僱。
我設法選擇的值如下:
function saveProjectStatus(e) {
debugger;
var grid = e.sender;
var row = grid.select();
var currentDataItem = grid.dataItem(this.select());
var selectedValue = currentDataItem.Text;
// var data = grid.dataItem("tr:eq(1)");
// var dataItem = grid.dataItem($(this).closest('tr'));
// var uid = currentDataItem.uid; //.Name;
// var dataContext = grid.dataSource.getByUid(uid);
// var parentRow = e.wrapper.closest("tr");
//var uid = $(e)parent().parent().attr('data-uid');
//var dataContext = grid.dataSource.getByUid(uid);
}
但我不能爲專案編號做同樣的!在過去的一個小時裏,我曾嘗試過幾次(都是上面提到的),但沒有成功。
我也很高興在DOM中隱藏行而不是獲取ProjectId,如果這也是可以的。
如果可以,請幫助。
非常感謝提前。
@C更清晰沒有下拉列表僅在一列中,是的,我想要捕獲該行的Id或將其從dom中隱藏。謝謝。 –
該功能將讓您訪問選定的行項目ID – CSharper
我從哪裏來的? @C Sharper –