Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
575 views
in Technique[技术] by (71.8m points)

asp.net mvc - DevExpress MVC GridView - How to get cell click event

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.

This is what I have for rows:

Html.DevExpress().GridView(settings =>
{
    // removed a lot of code here
    settings.ClientSideEvents.RowDblClick = "OnGridRowDblClick";
}).Bind(Model).GetHtml()

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...