简体   繁体   中英

infragistics webdatagrid get selected cell from keydown event in client side

I have build an infragistics webdatagrid in c# :

        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.

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".

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 :

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. This is my 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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