Skip to Content

How to change class name of each Item of LIST Control

Hi All,

I have used LIST Control in my view. I want to change style(Different Background Images for different items ) of each Item in the LIST. So I basically trying for to change the class name dynamically in controller.

Please suggest appropriate(best practice) solution.

Thanks in Advance !!

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on Oct 12, 2018 at 12:03 PM

    Hi,

    do you really want to change the class name (which means removing a default class and adding a new class) or would it be sufficient to just add a new class to all item (the latter case is way easier)?

    Are the items bound to the list? If so, you can simply add the new class to the template and all clones will have this class as well.

    Regards,

    Marius

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Avinash,

      ok, so this requirement seems to be very special. In this case I would attach a onAfterRendering() hook to the template list item and use 'getBindingContext().getPath()' to identify the index of the list item. With this you can call 'this.$().addClass()' to attach a new class to each item.

      I wouldn't call this approach "best practice" since the requirement itself seems to be the actual issue. However, this solution will work independent of the SAPUI5 version and doesn't have a negative impact on the performance.

      Regards,

      Marius

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.