Category: UI Widgets
Updated

This solution is summarized from an archived support forum post. This information may have changed. If you notice an error, please let us know in Discord.

How to stay on selected row after updating data of row in a table?

Issue

I am having an issue in the 'Customer Support Dashboard' app where after updating data in a row of a table widget, the active row jumps back to the first row in the list. I searched for similar issues and found one on GitHub related to the Table widget's PrimaryKey and Sorting features. I tried turning off sorting and filtering but that didn't work, only adding a primary key fixed the issue. It turns out that providing a primary key is necessary for retaining the selected row and not a bug.

Resolution

The issue where the active row jumps back to the first row in a table widget after updating data can be fixed by setting a Primary Key for the table. This is not a bug and is necessary for retaining the selected row after any action by the user, including sorting and filtering. Here is an example of setting the primary key "id" for a table:

// Set primary key for table
tableWidget.setPrimaryKeyColumns(["id"]);

Once the primary key is set, the selected row should be retained even after updating data or applying sorting to the table.