2

Using AG Grid we populate column defs array with column names returned by back end

Consider the array below , populated with data returned by the back end :

columnDefs: [
    { headerName: 'column_1', field: 'column_value_1' },
    { headerName: 'column_2', field: 'column_value_2' },
    { headerName: 'column_3', field: 'column_value_3' }
]

What TypeScript syntax could be used to implement the pseudo snippet below ? :

given rowData = []
given rowOfValues = [ row_value_1 , row_value_2 , row_value_3 ] // From Back End
given rowOfColumnNames= [ column_value_1 , column_value_2 , column_value_3 ] // From Back End

for index = 0 ; while index < rowOfValues.size ; index++

 add to rowData  ( rowOfColumnNames[index] : rowOfValues[index] )

return rowData

As per AG_Grid specification , the resulting rowData array wouuld be as follows :

rowData = [ { 
column_value_1: 'row_value_1', column_value_2 'row_value_2', column_value_3: row_value_3 } 
];

1 Answer 1

1
for ( let i = 0 ; i < rowOfValues ; i++ ) {

    object = {};

    object[rowOfColumnNames[i]] = rowOfValues[i];

    rowData.push(object);

}

return rowData;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.