Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

252
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda