docs/versioned_docs/version-2.27.0/how-to/bulk-update-multiple-rows-in-table.md
For the purpose of this guide, it's presumed that you've already established a successful connection to your data source. We'll use PostgreSQL for this example, but you can adjust the queries based on the SQL database that you are using.
SELECT * FROM <table name> // *replace <table name> with your table name*
Run the query on application load? option to execute the query automatically when the application starts.Data field of the Table:{{queries.users.data}}
Make editable to make the column editable.Allow Selection, Highlight Selected Row, and Bulk Selection option.const uniqueIdentifier = "id"
const cols = Object.values(components.table1.changeSet).map((col, index) => {
return {
col: Object.keys(col),
[uniqueIdentifier]: Object.values(components.table1.dataUpdates)[index][uniqueIdentifier],
values: Object.values(col),
};
});
const sql = cols.map((column) => {
const { col, id, values } = column;
const cols = col.map((col, index) => `${col} = '${values[index]}'`);
return `UPDATE users SET ${cols.join(", ")} WHERE id = '${id}';`;
});
return sql
Here the unique identifier is id and Table component's name is table1. You can update the unique identifier if you are using a different column as a unique identifier. You can also update the Table name if you have renamed it, the default name is table1.
<div style={{textAlign: 'center'}}> </div>{{queries.runjs1.data.join(' ')}}
Save Changes event so that whenever a user will edit the Table and hit the Save Changes button the runjs1 query will run.fx next to the Loading state property.{{queries.users.isLoading || queries.update.isLoading}}
The data needs to reload once the update query runs since we want the Table component to be populated with the updated data.
This will refresh the table whenever the update query will be run.