JavaScript UI Libraries & Blazor Components Suite – Smart UI › Forums › DropDownList › Coloring list items
Tagged: color
- This topic has 12 replies, 3 voices, and was last updated 2 years, 3 months ago by
svetoslav_borislavov.
-
AuthorPosts
-
October 13, 2022 at 9:01 am #103848
tbettinazzi@axioma.it
ParticipantI need to color some list item in different colors.
The preferred resut would be to color the background of the list item.
I tried with color attribute (red or #e0e383 notations) but nothing changed nor in the background nor in the forground colors (I tested also in tour demo setting color=”red” in a smart-list-item with no result).
I tried using style=”background-color: red;” and I obtain a strange result : instead of seeing the background in the red color I see a thin red color line above the item.
How can I solve ?
Tks
The testcase
<!DOCTYPE html>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title>DropDownList Overview</title><meta charset=”utf-8″ />
<meta http-equiv=”X-UA-Compatible” content=”IE=edge” />
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<meta name=”viewport” content=”width=device-width, initial-scale=1.0, maximum-scale=1.0″ /><link rel=”stylesheet” type=”text/css” href=”../../../source/styles/smart.default.css” />
<link rel=”stylesheet” type=”text/css” href=”../../styles/demos.css” /><link rel=”stylesheet” type=”text/css” href=”styles.css” />
<script src=”index.js”></script></head>
<body class=”viewport”><smart-drop-down-list>
<smart-list-item style=”background-color: red;”>Item 1</smart-list-item>
<smart-list-item>Item 2</smart-list-item>
<smart-list-item>Item 3</smart-list-item>
</smart-drop-down-list>
<!– scripts –>
<script src=”../../../source/modules/smart.dropdownlist.js”></script>
<script src=”index.js”></script></body>
</html>-
This topic was modified 2 years, 4 months ago by
tbettinazzi@axioma.it.
October 13, 2022 at 9:37 am #103853svetoslav_borislavov
ParticipantHi,
Add the style to the smart-list-item-container class.
Give a class name to the desired list item and then apply a style like this:
.bg-red .smart-list-item-container {
background-color: red}
See a demo here: https://codepen.io/dkeamcaksoem/pen/KKRJNZB
Best Regards,
Svetoslav BorislavovSmart UI Team
https://www.htmlelements.com/October 13, 2022 at 10:51 am #103858tbettinazzi@axioma.it
ParticipantTks for the solution, however I don’t know, a priori, the color I should use and then is quite difficult to define all needed classes.
Is it possible to solve it using a style attribute (I can generate it at runtime) ?
The color attribute what is usefull for ?
Tks
October 13, 2022 at 11:54 am #103862svetoslav_borislavov
ParticipantHi,
You can set the style programmatically. Have a look at this example: https://codepen.io/dkeamcaksoem/pen/KKRJNZB
or
You can set a class for the list of items that you want to edit and use this class to select their inner element in the querySelectorAll.
Example: querySelectorAll(‘.my-items .smart-list-item-container’)
Best Regards,
Svetoslav BorislavovSmart UI Team
https://www.htmlelements.com/October 13, 2022 at 12:08 pm #103863tbettinazzi@axioma.it
ParticipantTks but this is not a solution in my environment :
- my page is generated at runtime and then I can’t know a priori how many dropdown list I’ve, nor the id of each, nor how many items in each dropdown list, nor the color of each one and then I can’t use a js to do the job
- not all items should be colored and each one could have its own color
The best solution, if possible, shoud be
<smart-list-item style=”background-color : myCololor;”> or something like that I can generate in a single shot.
Tks
October 13, 2022 at 4:09 pm #103865admin
KeymasterHi tbettinazzi,
If you wish, you can create a function which styles a listbox and you can pass a listbox instance as a function parameter. Unfortunately, inline styles like that are not supported.
Best regards,
Peter StoevSmart UI Team
https://www.htmlelements.com/October 24, 2022 at 11:02 am #103906tbettinazzi@axioma.it
ParticipantAnother question
is it possible to set the classes of single items by dataSource ?
Could You provide an example ?
Tks
October 24, 2022 at 11:48 am #103908svetoslav_borislavov
ParticipantHi,
It is not possible to set classes in the dataSource.
If you have any additional questions, do not hesitate to contact us!
Best Regards,
Svetoslav BorislavovSmart UI Team
https://www.htmlelements.com/October 24, 2022 at 12:38 pm #103909tbettinazzi@axioma.it
ParticipantTks for your answer, however it seems that loading data from a dataSource is faster than create many <smart-list-items> and than I’m in an impasse :
- if I use a dataSource I loose the coloration features I need
- if I use <smart-list-items> I get poor preformances when I’ve large dropdown list
Could You suggest a way to solve that problem ?
Tks
P.S. : Is there some url location where I can see what’s allowed in dataSource and what’s not ?
-
This reply was modified 2 years, 4 months ago by
tbettinazzi@axioma.it.
-
This reply was modified 2 years, 4 months ago by
tbettinazzi@axioma.it.
October 25, 2022 at 6:27 am #103914svetoslav_borislavov
ParticipantHi,
You can do the following:
- Set a dataSource with the items and in the object, you can add a property for the class
- ForEach the dataSource and for each item, you can get the relevant element and apply the element’s class
Please look at the demo here: https://codepen.io/svetoslavb04/pen/OJEJXbe
Hope this helps!
Best Regards,
Svetoslav BorislavovSmart UI Team
https://www.htmlelements.com/October 25, 2022 at 2:52 pm #103915tbettinazzi@axioma.it
ParticipantTks, more or less solved.
I still have a problem, when the dropdown list opens I see the following effects :
- all elements have the correct height (setted by a class) but the last one which is larger (eg 50px vs 20px)
- down of the last element I’ve a lot of white space (more or less 50px)
Here my css definitions :
smart-drop-down-list {
min-height: 35px;
height: auto;
}.smart-list-item-container img {
width: 100%;
height: 100%;
}smart-list-item .smart-content,
smart-list-item .smart-overlay,
smart-list-item,
smart-drop-down-list {
height: 100px;
}.smart-list-item-container .image-description {
display: block;
position: absolute;
z-index: 99999;
top: 0;
left: 70%;
}I can provide You a printScreen of the noisy effects.
Tks
-
This reply was modified 2 years, 4 months ago by
tbettinazzi@axioma.it.
-
This reply was modified 2 years, 4 months ago by
tbettinazzi@axioma.it.
October 26, 2022 at 7:44 am #103918tbettinazzi@axioma.it
ParticipantI reproduced at least aprtially the problem on Your example (but I was not able to save it).
I simply added a new class.
This is the modified css
html, body { padding: 10px; }
.bg-red .smart-list-item-container {
background-color: red;
}smart-drop-down-list {
min-height: 35px;
height: auto;
width: 300px;
}
.elemento_list_item {
height: 20px;
}.elemento_list_item .smart-content {
height: 20px;
}And this is the modified js
window.onload = () => {
const dropDownList = document.querySelector(‘smart-drop-down-list’);
dropDownList.dataSource = [
{ label: “WAM ROMANIA”, value: “AF”, class: ‘bg-red’ },
{ label: “WAM PRODUCT”, value: “AA” }
]dropDownList.dataSource.forEach(element => {
const item = dropDownList.getItem(element.value)
console.log(item);
item.classList.add(“elemento_list_item”);
item.classList.add(element.class);
});}
Tks
-
This reply was modified 2 years, 3 months ago by
tbettinazzi@axioma.it.
October 26, 2022 at 8:16 am #103920svetoslav_borislavov
ParticipantHi,
There is a property for the items’ height: ‘item-height’
Could you, please look at the example: https://codepen.io/svetoslavb04/pen/OJEJXbeBest Regards,
Svetoslav BorislavovSmart UI Team
https://www.htmlelements.com/ -
This topic was modified 2 years, 4 months ago by
-
AuthorPosts
- You must be logged in to reply to this topic.