samedi 13 juin 2020

Set Focus to Row Checkbox in Ag-grid

I'm using plain vanilla javascript and have been unable to find a way to set focus to a checkbox in a row. When deselecting one of multiple rows, the focus is left in the checkbox that was just deselected. When only one row remains selected, I would like to move the focus to that checkbox.

These are my grid options: columnDefs:columnDefs, rowSelection:'multiple', rowDeselection:true, rowHeight:26, suppressCellSelection:true, onRowSelected:onRowSelected

Here is the function:

function onRowSelected(objRow) {
    var objFocusedCell = gridOptions.api.getFocusedCell();
    var strImageFile = gridOptions.api.getDisplayedRowAtIndex(objFocusedCell.rowIndex).data.ImageFile;
    if (gridOptions.rowSelection == 'multiple') {
    // I test row selection here because this function may also be used with single row grid option
        var arySelectedNodes = gridOptions.api.getSelectedNodes();
        var intSelectedCount = gridOptions.api.getSelectedRows().length;
        if ((objRow.node.isSelected()) && (intSelectedCount < gridOptions.api.getDisplayedRowCount())) {
            if (gridOptions.api.getDisplayedRowAtIndex(objFocusedCell.rowIndex).data.Expires > fncNowString()) {
                document.getElementById("theImage").src = gblPath + 'Items/' + strImageFile + "?asof=" + gblAsOf;
            } else {
                document.getElementById("theImage").src = 'expired.jpg';
            }
        } else {
            doHome();
            if (intSelectedCount == 1) {
                // CODE TO SET FOCUS WOULD GO HERE
            }
        }
        doBtnEnable('btnSlideshow',(intSelectedCount > 1));
    } else {
        document.getElementById("theImage").src = gblPath + 'Items/' + strImageFile + "?asof=" + gblAsOf;
    }
}



Aucun commentaire:

Enregistrer un commentaire