How do I auto-select newly added row in Table widget?

This question was asked on Discord by a user kraftathlete, following is the use-case:

How can I auto-selected the latest added row in a table?


For this, we can use the Appsmith store to save the last selected row in the table with a click of the button and on the default selected row property of the table widget you can bind {{appsmith.store.saveLastSelectedRow + 1}}


{{ 
 storeValue("saveLastSelectedRow", Table1.selectedRowIndex);
  UpdateQuery.run(
    () => SelectQuery.run(),
    () => showAlert("Did NOT Update!", "error")
  );
}}