Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SAPUI5/OpenUI5: CSS for custom control?

Tags:

sapui5

I am currently working on a custom control in SAPUI5/OpenUI5 and I am wondering how I can get the required CSS into the application. Where would I place the CSS code specific for my control? And how do I load it then from the control? I could not find anything in the documentation....

Thanks and best regards, Daniel

like image 315
Daniel Avatar asked May 27 '14 13:05

Daniel


3 Answers

In this tutorial, it's described how to use CSS in the renderer of custom controls.

If you're not using a custom renderer, you can attach CSS like to any other control like described here.

Always make sure that you load the CSS file e.g. in your html file.

Edit:

According to the comments jQuery.sap.includeStyleSheet() solved it.

like image 51
Tim Gerlach Avatar answered Oct 04 '22 14:10

Tim Gerlach


At the time of writing this, you require sap/ui/dom/includeStylesheet and call it within your init function.

Example:

sap.ui.define(
    [
        'sap/ui/core/Control',
        'sap/ui/dom/includeStylesheet'
    ],
    function (Control, includeStylesheet) {
        'use strict';

        return Control.extend('Example.control.MyControl', {
            // some more boilerplate code

            init: function () {
                includeStylesheet('../css/mycontrol.css');
            }
        });
    }
);
like image 34
pinki Avatar answered Oct 04 '22 13:10

pinki


You should create all your custom controls in a control library with a theme. https://github.com/SAP/openui5/blob/master/docs/controllibraries.md

Loading the theme in the sapui5 bootstrap causes the load of the library.css file in your control library with the same theme name (e.g. "sap_bluecrystal").

like image 25
Dominik Feininger Avatar answered Oct 04 '22 13:10

Dominik Feininger