Quantcast
Channel: SCN: Message List - SAPUI5 Developer Center
Viewing all articles
Browse latest Browse all 8124

Changing color of table cells with JSONModel

$
0
0

Hi there,

 

I need to change background / font color of table cells in a table bound to a JSONModel.

There already exists a thread which describes how to do that, but the solution mentioned there seems to work only for ODataModel, and also for that model type it's not working solid (for example the color of the cell gets lost when resizing the column).

 

Since I really need that feature, I dare to ask this quesion a second time related to the JSONModel.

 

Here's a code snipped (based on the method used in the other thread) to accomplish this task.

 

var oMappedDataJson = new sap.ui.model.json.JSONModel();
oMappedDataJson.setJSON('{"d":{"results":[{"COLOR": "0d233a"},{"COLOR": "8bbc21"}, {"COLOR": "785941"}]}}');
var oMappedTable = new sap.ui.table.Table();

var tvColor = new sap.ui.commons.TextField().bindProperty("value","COLOR", function(cellValue){
// change font color of the textfield
//$('#' +  this.getId()).css("color","yellow"); // also doesn't work
$('#' +  this.getId()).css("background-color","#" + cellValue);     return cellValue;
});

// Table Column-Definition
oMappedTable.addColumn(new sap.ui.table.Column({label: new sap.ui.commons.Label({text:"Color"}), template: tvColor}));

oMappedTable.setModel(oMappedDataJson);
oMappedTable.bindRows("/d/results");
oMappedTable.placeAt("content");

 

 

Thanks for your help!


Viewing all articles
Browse latest Browse all 8124

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>