Set Selected Row Focus

Set Selected Row Focus

ToybToyb Posts: 19Questions: 9Answers: 1

I'm using "rowId:" to capture the current selected row before refreshing my datatable. After refresh I can re-select the row.

            ActiveTable.api().rows().deselect();
            ActiveTable.api().row("#" + ActiveRowId).select();

QUESTION: How can I set the cell focus on the selected row?

PROBLEM: After refreshing data and setting the previously selected row the focus is lost and using arrow keys no longer moves the row selection to the next row.

Thank for the help!

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954

    Are you using the keyTable extension? If so then maybe you can use cell().focus().

    Kevin

  • ToybToyb Posts: 19Questions: 9Answers: 1

    Yes, using the KeyTable Extension.

    My code has progressed to this and still does not work...

      ActiveTable.api().rows().deselect();
      ActiveTable.api().row("#" + ActiveRowId).select();
      ActiveTable.api().cell(ActiveTable.api().row("#" + ActiveRowId), 0).focus();
      ActiveTable.api().cell(ActiveTable.api().row("#" + ActiveRowId), 0).node().classList.add("focus");
    
    
  • ToybToyb Posts: 19Questions: 9Answers: 1

    Ok, found the problem.

    CODE NEEDED:

    ActiveTable.api().row("#" + ActiveRowId).select();
    ActiveTable.api().cell(ActiveTable.api().row("#" + ActiveRowId), 0).focus();
    

    PROBLEM: My program disables user keystrokes during data refresh. While preventing user keystrokes it apparently prevents code behind from working, even though .select was being set correctly, etc. and appeared to be working.

    Keys needs to be enabled when setting focus...

    ActiveTable.api().keys.disable();
    

    Thanks for the help!

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954
    Answer ✓

    You can probably do something like this:

    ActiveTable.api().cell("#" + ActiveRowId, 0).focus();
    

    It will save an extra API call. Checkout the row-selector and column-selector for the cell() API for more details.

    Kevin

Sign In or Register to comment.