DevExpress MVC GridView - 如何获取单元格单击事件 [英] DevExpress MVC GridView - How to get cell click event
问题描述
使用DevExpress的GridView,我想在选择一个单元格(或者只是点击)时触发(客户端)事件。
Using DevExpress's GridView, I would like to trigger a (clientside) event when a cell is selected (or simply clicked on).
已经有一种方法获取整个行的点击事件,但是没有文字和文档都给了我任何线索,如何为单元格实现这一点。
There already is a way to get the click events for an entire row, but neither fiddling around nor the documentation gives me any clue how to achieve this for cells.
这是我对行的:
Html.DevExpress().GridView(settings =>
{
// removed a lot of code here
settings.ClientSideEvents.RowDblClick = "OnGridRowDblClick";
}).Bind(Model).GetHtml()
当双击一行时,会导致调用JavaScript函数 OnGridRowDblClick
。理想情况下,应该有一些类似于
Which will cause the javascript function OnGridRowDblClick
to be called when a row is double clicked. Ideally there should be something like
settings.ClientSideEvents.CellClick =OnCellClick;
但是,这不存在,也不能找到任何东西来实现。
However, this does not exist, nor can I find anything to achieve this.
推荐答案
通过处理 GridViewSettings.HtmlDataCellPrepared 事件,可以为单个DataCell附加所需的客户端处理程序:
It is possible to attach the required client-side handler for an individual DataCell by handling the GridViewSettings.HtmlDataCellPrepared event:
function OnCellClick(visibleIndex, fieldName) {
alert(visibleIndex + " " + fieldName);
}
@Html.DevExpress().GridView(settings => {
...
settings.HtmlDataCellPrepared = (sender, e) => {
e.Cell.Attributes.Add(
"onclick",
string.Format("OnCellClick('{0}', '{1}');", e.VisibleIndex, e.DataColumn.FieldName)
);
};
}).Bind(Model).GetHtml()
这篇关于DevExpress MVC GridView - 如何获取单元格单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!