Need a special offer?Find out if your project fits.
+

flat grid - get data property

Answered
Dejan asked on November 22, 2022

Hi, I am trying to change background of one column data dynamically based on values from JSON (like BG color). 
I experimented with customizeCellFunction and closest I got is defining BG color field as ID and refer to it like this: 
function customizeCellFunction(cell, data) {
if (!(data.hierarchy && data.hierarchy.uniqueName == "koren")) return;
let newText =
`<p style='background-color:${data.recordId}'>${data.escapedLabel}</p>`;
if (data.type == "header" && data.member) {
let parts = cell.text.split(data.escapedLabel);
if (parts.length == 2) {
newText = parts[0] + newText + parts[1];
}
cell.text = newText;
} else if (data.type == "value" && (data.member || data.isDrillThrough)) {
cell.style['z-index'] = 1;
cell.text = newText;
}
}
 
And it works. 
 
Then I wanted to implement some URLs and aditional other BG fields but I got stuck since only 1 ID is supported.
I then saw option to use 'property' in JSON dataset but can't figure out how to refer to certain property in customizeCellFunction. 
I searched through examples and find for instance how to create 'alerts' etc. from 'properties' but struggle how to use them in customizeCellFunction. 
Please note I need this only for flat view.

4 answers

Public
Maksym Diachenko Maksym Diachenko Flexmonster November 24, 2022

Hello, Dejan!

Thank you for your question.

While using the flat mode, the property fields are stored inside the member.properties object inside the CellDataObject. Please note that you should also specify the certain string hierarchy. You will be able to access this property only from cells of this hierarchy:

"bgColor": {
type: "property",
    hierarchy: "koren"
},

You are welcome to check the JSFiddle example using multiple properties for customizing cells: https://jsfiddle.net/flexmonster/0rn2dqya/ 

Looking forward to hearing your feedback.

Best Regards,
Maksym

Public
Maksym Diachenko Maksym Diachenko Flexmonster December 1, 2022

Hello, Dejan!

Hope you are doing well.
Our team is wondering if you were able to check the provided example of using the property field for customizing cells in flat view.
Please let us know if this solution works for you.

Best Regards,
Maksym

Public
Dejan December 1, 2022

Hello, Maksym! 
Apologies for not replying and testing sooner. I've now managed to test this one and confirm - your suggested syntax and approach works as expected! 

Public
Maksym Diachenko Maksym Diachenko Flexmonster December 1, 2022

Hi, Dejan!

Thank you for your feedback.
We are glad to hear that the provided solution worked for you.
Feel free to contact us if more questions arise.

Best Regards,
Maksym

Please login or Register to Submit Answer