Skip to Content

How to add css style to a control within init() ?

Dear all,

In the init() of one controller, I want to change the background color of the first item of sap.m.list after data is fetched. I tried two way:

a. oFirstItem.addStyleClass("darkerBackground");

b. oFirstItem.$().css('background-color', '#e8eff6 ');

However, none of above works. I'm sure oFirstItem is what to be changed.

What should I do?

Thank you very much in advance :)

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Feb 26 at 02:19 PM

    Hi Ying,

    First of all, to change the color of first item in the list, you should do it on the updateFinished event of the list instead of the onInit method of the controller since the length of the list could be 0 in onInit.

    To update the background colour of the 0th item, you can update it using the following :

    var firstListItemId = list.getItems()[0].sId

    $("div#" + firstListItemId).attr("style", "background-color: rgb(229, 41, 41) !important");

    Thanks,

    Vaibhav Maheshwari

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 26 at 01:36 PM

    The onInit function is called prior to the controls being available. This should be done using the dataReceived event of the data model.

    Regards,

    Jamie

    Add comment
    10|10000 characters needed characters exceeded