Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

251
Visualizações
Put background color with values from OData SAPUI5/JAVASCRIPT

I need to set background colors with the values that I'm getting from the OData. I have the following code:

oModel.read("/EspCoSet", {
    filters: [aFilters],
    success: function (oD, oR) {
        var oResults = oD.results;
        for (var i = 0; i < oResults.length; i++) {
            var color_fondo = oResults[i].ColorFondo;
            var color_texto = oResults[i].ColorTexto;
        }
    },
    error: function (oE) {
        console.log("Error");
    }
});

In the variable "color_fondo" I'm saving the value of the color in HEX like this "FFFFFF". Are there any way to put this value to the corresponding cells witouth touch css. I watched this methods:

[data-esp="Hospitalizado"] * {
  background-color:   #FFFFFF !important;
  color: red !important;
}

but if I do like this I need to write the information again ( the information that comes from the OData) and then the value from the OData doesn't have any use. Is posible?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I found a solution, that was a merge between some answers in Internet. To get the colors from the OData I change a little bit the backend. My table before was with colors in HEX, now I changed for letters like this:

color_fondo  |  color_texto
WHITE        |  BLACK
BLUE         |  RED  
GREEN        |  BLACK

Then, in the css I put the name of the color as a class, like this:

.BLUE {
    background-color: #9dcfdd !important;
}

and finally in the controller, when I read the model and I get the respective color for each patient, I get the item of each cell and with addStyleClass I apply the color_fondo that is the variable that comes from the OData.

oModel.read("/EspCoSet", {
    filters: [aFilters],
    success: function (oD, oR) {
        var oResults = oD.results;
        for (var i = 0; i < oResults.length; i++) {
            var color_fondo = oResults[i].ColorFondo;
            var color_texto = oResults[i].ColorTexto;
            var aItems = oTable.getItems();
            aItems[i].addStyleClass(color_fondo);
            aItems[i].addStyleClass(color_texto);
        }
    },
    error: function (oE) {
        console.log("Error");
    }
});

and finally I get the colors in my frontend. I left this here because I couldn't find any example of this that get the colors from the OData, may can help someone. Btw sorry for my english, I hope that all was clear.

NOTE: For the text color you need to put in the css *:

.RED *{
    color: #c63637 !important;
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda