@Html.EJS().DropDownList("employees").DataSource((IEnumerable<GameList>)ViewBag.data).Placeholder("Select an employee").PopupHeight("270px").Fields(new DropDownListFieldSettings { Value = "Game" }).ItemTemplate(
"<div><div class=\"ename\"> ${Game} </div></div>").ValueTemplate(
"<div style=\"width:100%;height:100%;\"><div class=\"name ${Class} \"> ${Game} </div></div>").Render()
<style>
.e-ddl .e-blue {
background-color: yellow !important;
color: blue !important;
}
.e-ddl .e-red {
background-color: yellow !important;
color: red !important;
}
.e-ddl .e-green {
background-color: yellow !important;
color: green !important;
}
.e-ddl .e-yellow {
background-color: gray !important;
color: yellow !important;
}
.e-ddl .e-orange {
background-color: yellow !important;
color: orange !important;
}
</style>
[Model]
public class GameList
{
public string Id { get; set; }
public string Game { get; set; }
public string Class { get; set; }
public List<GameList> GameLists()
{
List<GameList> game = new List<GameList>();
game.Add(new GameList { Id = "Game1", Game = "American Football", Class="e-red" });
game.Add(new GameList { Id = "Game2", Game = "Badminton", Class="e-green" });
game.Add(new GameList { Id = "Game3", Game = "Basketball", Class="e-blue" });
game.Add(new GameList { Id = "Game4", Game = "Cricket" , Class="e-yellow"});
game.Add(new GameList { Id = "Game5", Game = "Football", Class="e-orange" });
return game;
}
} |
@Html.EJS().DropDownList("employees").DataSource((IEnumerable<GameList>)ViewBag.data).Change("onChange").Placeholder("Select an employee").PopupHeight("270px").Fields(new DropDownListFieldSettings { Value = "Game" }).ItemTemplate(
"<div><div class=\"ename\"> ${Game} </div></div>").ValueTemplate(
"<div style=\"width:100%;height:100%;\"><div class=\"name \"> ${Game} </div></div>").Render()
<script>
function onChange(args) {
if (args.itemData.Id = "Game3") {
var valueTemplateItem = document.querySelector(".e-input-value .name");
valueTemplateItem.classList.add('e-blue');
}
}
</script>
<style>
.e-ddl .e-blue {
background-color: yellow !important;
color: blue !important;
}
.e-ddl .e-red {
background-color: yellow !important;
color: red !important;
}
.e-ddl .e-green {
background-color: yellow !important;
color: green !important;
}
.e-ddl .e-yellow {
background-color: gray !important;
color: yellow !important;
}
.e-ddl .e-orange {
background-color: yellow !important;
color: orange !important;
}
</style> |
@Html.EJS().DropDownList("employees").DataSource((IEnumerable<GameList>)ViewBag.data).Close("popupClose").Placeholder("Select an employee").PopupHeight("270px").Fields(new DropDownListFieldSettings { Value = "Game" }).ItemTemplate(
"<div><div class=\"ename\"> ${Game} </div></div>").ValueTemplate(
"<div style=\"width:100%;height:100%;\"><div class=\"name \"> ${Game} </div></div>").Render()
<script>
function popupClose(args) {
if (this.value == "Basketball") {
var valueTemplateItem = document.querySelector(".e-input-value .name");
valueTemplateItem.setAttribute("style", "background-color: red");
}
}
</script> |
@(Html.EJS().DropDownList("games")
.Placeholder("Select a game")
.DataSource((IEnumerable<GameList>)ViewBag.gamelist)
.Fields(new DropDownListFieldSettings { Text="Game" , Value = "Id" })
.ItemTemplate("<div><div class=\"box\"></div>" + "<div class=\"ename\"> ${Game} </div></div>")
.ValueTemplate("<div><div class=\"box\"></div>" + "<div class=\"ename\"> ${Game} </div></div>")
.Open("popupOpen").Change("popupClose").Render())
<script>
var colorData = @Html.Raw(Json.Encode(ViewBag.colorlists));
function popupClose(args) {
console.log("VALUE: " + this.Value); //Its value is always: 1
if (args.itemData.Id == 2) {
var valueTemplateItem = document.querySelector(".e-input-value .ename");
valueTemplateItem.setAttribute("style", "background-color: red");
}
}
</script> |