Join the Team Forms community

Updated 4 months ago

Applying an On Change from inside a Data Grid to the Row that it is triggered from

At a glance

The community member is building a Data Grid with multiple components, and when the 'employees' component is changed, they want to update the entire row to reflect different data. They have tried setting the entire Data Grid to the updated row, but cannot find a way to update just the row that the change is happening in.

In the comments, another community member suggests updating the row variable directly. They provide steps for synchronous logic, including setting the "redraw on" property to "any change" and adding code to the "On Change" property of the component that triggers the change.

Another community member asks about asynchronous logic and using data sources. The response suggests that ideally the SharePoint drop-down (employee object) should contain all the fields needed to populate the rest of the columns, but if that's not possible, the row variables can be set asynchronously, and instance.root.redraw() should be called to manually reflect the changes.

<answer>The easiest way to achieve this is by updating the row variable. For example, the steps below should work if using synchronous logic: Open the settings for the components/columns you will be updating and ensure you set the "redraw on" property to "any change". This step ensures the values you set in JavaScript are re-drawn and visible in the form. Open

I am building a Data Grid that has multiple components on it and when the component labelled 'employees' is changed, I want the entire row to be updated to reflect different data that I have mapped from data sources.

Running the following line sets the entire Data Grid to the row that I wanted set,

Plain Text
      instance.root.getComponent('DataGrid').setValue(updatedRow) 

however I can't find a way to update just the row that the change is happening in.

Marked as solution

Hi Callum,

The easiest way to achieve this is by updating the row variable. For example, the steps below should work if using synchronous logic:

  1. Open the settings for the components/columns you will be updating and ensure you set the "redraw on" property to "any change". This step ensures the values you set in JavaScript are re-drawn and visible in the form.

  2. Open the settings for the component that will trigger the change (e.g. the employee) and add the following code to the On Change property. Note that you will need to adapt the code below to match your specific form and requirements.

JavaScript
const vehicle = instance.getValue() //Returns the value of the current component

row.brand = vehicle.brand
row.model = vehicle.model


Here is an example of the output:

View full solution
A
C
1 commentΒ·2 replies

Hi Callum,

The easiest way to achieve this is by updating the row variable. For example, the steps below should work if using synchronous logic:

  1. Open the settings for the components/columns you will be updating and ensure you set the "redraw on" property to "any change". This step ensures the values you set in JavaScript are re-drawn and visible in the form.

  2. Open the settings for the component that will trigger the change (e.g. the employee) and add the following code to the On Change property. Note that you will need to adapt the code below to match your specific form and requirements.

JavaScript
const vehicle = instance.getValue() //Returns the value of the current component

row.brand = vehicle.brand
row.model = vehicle.model


Here is an example of the output:

What if it is an asynchronous logic, if I need to use data sources in the logic?

Ideally the SharePoint drop-down (employee object) should contain all the fields you need to populate the rest of the columns to avoid asynchronous logic which could have performance impacts and complicates the code.

However, if its unavoidable you can still set the row variables properties asynchronously, but you need to call instance.root.redraw() after to manually reflect the changes in the form response. Here is an example which uses a delay function to simulate an async function call.

JavaScript
function delay(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}

async function updateColumns(){
    const vehicle = instance.getValue() 
    await delay(1000)
    row.brand = vehicle.brand
    row.model = vehicle.Model
    instance.root.redraw()
}

updateColumns()