27
Views
2
Comments
Solved
[OutSystems Data Grid] How to set the default value for data grid dropdown column
outsystems-data-grid
Reactive icon
Forge asset by OutSystems
Application Type
Reactive
Service Studio Version
11.54.78 (Build 63596)

Hi All,

How to set the default value for the data grid dropdown column?

I have a score column with dropdown values (1, 2, 3). So, when the grid is initialized, can we set the default value as 1 for each row of the score column?

Regards,

Vinod

Grid.oml
2022-11-12 11-28-30
Gonçalo Martins
Staff
Solution

Hi @Vinod Kumar R 

The dropdown values come from the database so you need to manage that at the database level when it's a foreign key from another entity.

In your case, given the fact you're using a different data source with no relation to the Product entity you can add the following script on the Initialize event handler from the Grid block:

let flexGrid = OutSystems.GridAPI.GridManager.GetGridById($parameters.GridWidgetId).provider;

// Set the default value for the dropdown column in the initial data
flexGrid.itemsSource.items.forEach(function (item) {
    // If Score has no value
    if (item.Score == null || item.Score == undefined || item.Score === '') {
        // set the ID of the Score to set as default
        item.Score = 3; 
    }
  
});

Hope it helps!

Cheers,
GM

2023-03-08 10-32-19
Vinod Kumar R
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.