Reputation: 3502
In XML view for i have :
<Table id="testtable" xmlns="sap.ui.table"
rows="{/testdata}"
alternateRowColors="true">
<columns>
<Column hAlign="Center" label="Col1">
<template>
<m:Text text="{dataX}" wrapping="false" />
</template>
</Column>
<Column hAlign="Center" label="Col2">
<template>
<m:Text text="{dataY}" wrapping="false" />
</template>
</Column>
<Column label="Col3">
<template>
<m:HBox>
<core:Icon src="sap-icon://show" color="{ parts : [ 'test'], formatter: '.setIconColour'}" />
<core:Icon src="sap-icon://edit" color="{ parts : [ 'test' ], formatter: '.setIconColour'}" />
<core:Icon src="sap-icon://print" color="{ parts : [ 'test' ], formatter: '.setIconColour'}" />
</m:HBox>
</template>
</Column>
</columns>
</Table>
In controller (formatter function is as):
setIconColour: function (value) {
if (value === 1) {
return "#007bff";
} else if (value === 2) {
return "Positive";
} else if (value === 3) {
return "Negative";
}
}
The sample data is as:
{"testdata": [
{ "dataX": 1, "dataY": "testdata", "test": 0},
{ "dataX": 2, "dataY": "testdata", "test": 2},
{ "dataX": 3, "dataY": "testdata", "test": 3},
{ "dataX": 4, "dataY": "testdata", "test": 1}
]}
This changes color of Icon Properties based on test
value ,after this may i know how can i change the color of only last row icons or (only row) if only one row exists (rest all have same properties as per formatter function)
I am trying to do this as :
var tabItems = this.byId("testtable").getRows();
var cells = tabItems[testdata.length-1].getCells(); // get last row cells
cells[8].mAggregations.items[0].setColor(
"#000000"); // at this path i have all 3 icons and trying to set color here (items[0],items[1],items[2] --> 3 icons)
But this approach doesn't work as expected giving weird results until page refresh , hope there would be a better way , any help or guiding links are much appreciated TIA
Upvotes: 0
Views: 219
Reputation: 41
Maybe you can add index your JSON then you can give index and length of JSON to your formatter.
JSON like this:
{"testdata": [
{ index: 1, "dataX": 1, "dataY": "testdata", "test": 0},
{ index: 2, "dataX": 2, "dataY": "testdata", "test": 2},
{ index: 3, "dataX": 3, "dataY": "testdata", "test": 3},
{ index: 4, "dataX": 4, "dataY": "testdata", "test": 1}
]}
Formatter:
setIconColour: function (value, index, length) {
//
}
Upvotes: 1