Reputation: 21
I've been trying to use CustomData in sap.ui.TreeTable. I pass the value for CustomData from my ODataModel but I've been getting errors like
CustomData with key cssColor should be written to HTML of Element sap.m.Text#__text25-__clone22 but the value is not a string.
So I used formatter to pass a string to the value:
<t:Column
resizable="false"
width="5.5rem"
sortProperty="CMPlan"
>
<t:multiLabels>
<Text
text="{i18n>currMonth}"
textAlign="Center"
width="100%"
class="boldHeader"
/>
<Text
text="{i18n>plan}"
textAlign="Center"
width="100%"
class="boldHeader"
/>
</t:multiLabels>
<t:template>
<Text
width="100%"
text="{treeJSONModel>Plan}"
>
<customData>
<core:CustomData
key="cssColor"
value="{
path: 'treeJSONModel>colorCode',
formatter: '.formatter.colorString'
}"
writeToDom="true"
/>
</customData>
</Text>
</t:template>
</t:Column>
And in my formatter, I have a function like below:
colorString: function(value) {
if (value === "YELLOW") {
return "YELLOW";
} else {
return "noColor";
}
},
The number of error I get has been reduced but still I see this error in my console
CustomData with key cssColor should be written to HTML of Element sap.m.Text#__text37-__clone40 but the value is not a string.
Any solutions to help me rectify this is very much appreciated.
Upvotes: 2
Views: 2106
Reputation: 151
I had the same issue and found a (quick & dirty) way to handle the errors.
I followed your approach and made a formatter:
formatCell: function (iValue) {
try {
iValue.toString();
} catch (err){
iValue = "foo";
}
return iValue.toString();
}
basically I force the Value (in every possible way) to be a String...
It throws an error if you try toString()
on null
so I just assign a dummy String...
I assume the error only gets thrown if you assign null
to your customData
Upvotes: 1