Skip to Content
0

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

Feb 26 at 07:07 AM

31

avatar image

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 :)

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Vaibhav Maheshwari Feb 26 at 02:19 PM
2

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

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Hi Vaibhav,

I tried updateFinished event and it works well! Thank you so much!

0
Jamie Cawley
Feb 26 at 01:36 PM
0

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

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Hi Jamie, thank you so much for your information!

0