简体   繁体   English

infragistics webdatagrid从客户端的keydown事件中获取所选单元格

[英]infragistics webdatagrid get selected cell from keydown event in client side

I have build an infragistics webdatagrid in c# : 我在c#中构建了一个infragistics webdatagrid:

        var columnOne = new BoundDataField();
        columnOne.DataFieldName = "ColumnOne";
        columnOne.Key = "columnOne";
        columnOne.Header.Text = "columnOne";

        var columnTwo = new BoundDataField();
        columnTwo.DataFieldName = "ColumnTwo";
        columnTwo.Key = "columnTwo";
        columnTwo.Header.Text = "columnTwo";

        WebDataGridObject.DataKeyFields = "ColumnOne";
        WebDataGridObject.Columns.Add(columnOne);
        WebDataGridObject.Columns.Add(columnTwo);

I would like from javascript to update the cell from the column two when something is typed in the cell from the column one. 我想从javascript更新第二列中的单元格,当在第一列的单元格中键入内容时。

For example, my user starts typing a value in cell at line 3 and column one, the cell at line and column two must be automatically updated with a constant value, like "updated". 例如,我的用户开始在第3行和第1列的单元格中键入值,第2行和第2列的单元格必须使用常量值自动更新,例如“updated”。

To do that, I am a bit struggling, I have attach a lot of client events from my c#, and I think that the one usefull is the keydown : 要做到这一点,我有点挣扎,我从c#附加了很多客户事件,我认为有用的是keydown:

WebDataGridObject.ClientEvents.MouseDown = "WebDataGridView_MouseDown";
WebDataGridObject.ClientEvents.KeyDown = "WebDataGridView_KeyDown";
WebDataGridObject.Behaviors.EditingCore.Behaviors.CellEditing.CellEditingClientEvents.EnteredEditMode = "enteredEditMode";
WebDataGridObject.Behaviors.EditingCore.Behaviors.CellEditing.CellEditingClientEvents.ExitedEditMode = "exitedEditMode";

I would like my js keydown event handler, getting the column key of the cell currently edited, and if it's equals to "columnOne", update the value of the cell at the same line and on column two. 我想要我的js keydown事件处理程序,获取当前编辑的单元格的列键,如果它等于“columnOne”,则在同一行和第二列更新单元格的值。 This is my js : 这是我的js:

function WebDataGridView_KeyDown(webDataGrid, evntArgs) {


}

function WebDataGridView_MouseDown(webDataGrid, evntArgs) {
// this is where I am trying to get the column key of the currently edited cell
    webDataGrid.get_behaviors().get_selection().get_selectedRowsResolved()    [0].get_cell(3).get_text()
 }

var gridRef;
var cellRef;

function enteredEditMode(grid, args) {
    gridRef = grid;
    cellRef = args.getCell();
    if (cellRef._column._key === "headerName") {
        alert('toto');
    }
} 

function exitedEditMode(grid, args) {
    gridRef = null;
    cellRef = null;
}

To get the column key, you should try this: 要获取列键,您应该尝试这样做:

    webDataGrid.get_behaviors().get_selection().get_selectedRowsResolved()[0].get_cell(3).get_column().get_key();

or this: 或这个:

   webDataGrid.get_behaviors().get_selection().get_selectedRowsResolved()[0].get_cell(3).get_column()._dataFieldName

In order to get the column key of the cell that is going to be put in edit mode, it is recommended to use the eventArgs parameter. 为了获取将要进入编辑模式的单元格的列键 ,建议使用eventArgs参数。

Below you will find the two client events from where you can access this information (Column Key) 您可以在下面找到可以访问此信息的两个客户端事件(列键)

function WebDataGrid1_CellEditing_EnteringEditMode(sender, eventArgs)
{
    // Get the key of the currently edited cell
    var columnKey = eventArgs.getCell().get_column().get_key();
}

function ClientEvents_MouseDown(sender, eventArgs) {
    // Get the key of the currently edited cell
    var columnKey = eventArgs.get_item().get_column().get_key();
}

As you will see the difference is the getCell and getItem methods from eventArgs 正如您将看到的不同之处在于eventArgs中getCellgetItem方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM