Updating all cells within rows that were changed in table

Hi! I am bringing data from my MySQL database that has many many columns. There are multiple primary keys distinguishing between each row in the database Symbol, Plan ID, Model ID, and Execution Step. I often also duplicate these rows and change them (i.e. Duplicate one row and all of its columns, change the execution step from 0 -> 1 and then change one other column.

I am having trouble finding a way to update bulk rows. If this is not possible with my problem, I would like to update just the last row that I made changes to. Currently, this is what I am working with:

Here, I first filter the 4 primary keys to be what the selected row is, then I try to change it with changesetArray. Please advise what I am doing wrong/if there is any way that I can not only update the last row I changed but all the rows I changed.

Thank you in advance

Hi @yonkersyinks,

You can achieve the bulk update, but you'll need to create a script that gathers the primary key info from your table, then calls your update function for each row, passing in the required filter and update data.

The changeSetObject property has the row id from your table data, which you can use to collect you PK data. So on your table, set the Save event handle to be a script like the one below.

const changedRowIds = Object.keys(train_plan.changesetObject)
const changes = changedRowIds.map(rowId => {
  const {symbol, plan_id, model_id, execution_s} = train_plan.data[rowId]
  const changes = train_plan.changesetObject[rowId]
  return {
     filter: { symbol, plan_id, model_id, execution_s},
     changes
  }
})

// Now you have an array of objects with the changes and filter info you need. So call your updater function
// Do it as an array of promises in case you have a lot of change or a slow query.
const promises = changeData.map(change => {
  let {filter, changes} = change
  return yourQuery.trigger({additionalScope: {filter, changes}})
})
await Promise.all(promises)

//Refresh your table
train_plan.refresh()

And yourQuery would look like this:

image

(don't worry about all the red warnings)

1 Like