Retreive data from custom columns

Hello!
I am currently trying to get data from custom columns in a table to use in a bulk update, I have the following table:


to quickly select the colums. Now I want to use the save button in order to execute a bulk-update, the issue is that I have stored this in a column in my DB as a JSON string in the following form

{
  role: "premium", /* OR: "normal" */
  pages: {
    dashboard: "full", /* OR: "partial" OR: "none" */
    members: "full", /* OR: "partial" OR: "none" */
    activities: "full", /* OR: "partial" OR: "none" */
	campaigns: "full", /* OR: "partial" OR: "none" */
	media: "full", /* OR: "partial" OR: "none" */
	changelog: "full", /* OR: "partial" OR: "none" */
	administration: "full", /* OR: "partial" OR: "none" */
  }}

now I need to put the JSON string back together with whatever I enter in my custom columns. I haven't yet found a way to access the data, can anyone help me?
Thank you in advance !

you can use table1.getDisplayedData() to get an array of rows that includes custom columns and table1.data to get an array of rows without custom columns.

return table1.getDisplayedData().then((new_table_data) => {
  return table1.data.map((original_row, i) => ({
    rowID: original_row.id, //keep the rowID so we can reference the row later
    ...Object.keys(new_table_data[i]) //add all key/values including custom columns
      .filter(key => !Object.keys(original_row).includes(key)) //filter out columns that appear in both objects
      .reduce((acc, key) => ({...acc, [key]: new_table_data[i][key]}), {}) //Object.keys().filter() returns an array, we use .reduce to turn it into an object
  }))  
})

Thank you, I found a work around for my usecase by assigning a primary key of my table and then use .changesetObject!
I will give it a try next time :slight_smile:

1 Like