JavaScript/jQuery DropDownBox - Customize the Appearance
You can customize the text field and the drop-down button using the fieldTemplate and dropDownButtonTemplate. To adjust the drop-down field, use the dropDownOptions object that contains properties described in the Popup Configuration section.
jQuery
JavaScript
CSS
- $(function () {
- const fruits = [
- { id: 1, text: "Apples", image: "images/Apples.svg" },
- { id: 2, text: "Oranges", image: "images/Oranges.svg" },
- { id: 3, text: "Lemons", image: "images/Lemons.svg" },
- { id: 4, text: "Pears", image: "images/Pears.svg" },
- { id: 5, text: "Pineapples", image: "images/Pineapples.svg" }
- ];
- $("#dropDownBoxContainer").dxDropDownBox({
- value: fruits[0],
- dataSource: new DevExpress.data.DataSource({
- store: new DevExpress.data.ArrayStore({ data: fruits, key: "id" }),
- }),
- dropDownOptions: {
- title: "Fruits",
- showTitle: true,
- fullScreen: true,
- showCloseButton: true
- },
- dropDownButtonTemplate: function() {
- return $("<img />").attr("src", "images/icons/custom-dropbutton-icon.svg");
- },
- fieldTemplate: function (value, fieldElement) {
- return $("<div class='custom-item' />").append(
- $("<img />").attr("src", value.image),
- $("<div class='product-name' />").dxTextBox({ value: value.text, readOnly: true })
- );
- },
- contentTemplate: function(e) {
- const list = $("<div>").dxList({
- dataSource: e.component.option("dataSource"),
- selectionMode: "single",
- onSelectionChanged: function(arg) {
- e.component.option("value", arg.addedItems[0]);
- e.component.close();
- }
- });
- return list;
- }
- });
- });
- .custom-item {
- position: relative;
- min-height: 30px;
- }
- .custom-item > img {
- left: 1px;
- margin-top: 3px;
- max-height: 30px;
- width: auto;
- position: absolute;
- }
- .product-name {
- display: inline-block;
- padding-left: 45px;
- text-indent: 0;
- line-height: 30px;
- font-size: 15px;
- width: 100%;
- }
ASP.NET MVC Controls
Razor C#
CSS
- @(Html.DevExtreme().DropDownBox()
- .ID("dropDownBox")
- .DataSource(ds => ds.Array()
- .Key("ID")
- .Data(new JS("fruits"))
- )
- .Value(new JS("value"))
- .ContentTemplate(new TemplateName("list"))
- .DropDownButtonTemplate("<img src= 'images/icons/custom-dropbutton-icon.svg' />")
- .FieldTemplate(new TemplateName("field_template"))
- .DropDownOptions(o => o
- .Title("Fruits")
- .ShowTitle(true)
- .FullScreen(true)
- .ShowCloseButton(true)
- )
- )
- @using (Html.DevExtreme().NamedTemplate("list")) {
- @(Html.DevExtreme().List()
- .ID("list")
- .DataSource(new JS("component.option('dataSource')"))
- .SelectionMode(ListSelectionMode.Single)
- .OnSelectionChanged("innerList_selectionChanged")
- )
- }
- @using (Html.DevExtreme().NamedTemplate("field_template")) {
- <div class="custom-item">
- <img src="<% value.image %>">
- <div class="product-name">
- @(Html.DevExtreme().TextBox()
- .Value(new JS("value.text"))
- .ReadOnly(true)
- )
- </div>
- </div>
- }
- <script>
- const fruits = [
- { ID: 1, text: "Apples", image: "images/Apples.svg" },
- { ID: 2, text: "Oranges", image: "images/Oranges.svg" },
- { ID: 3, text: "Lemons", image: "images/Lemons.svg" },
- { ID: 4, text: "Pears", image: "images/Pears.svg" },
- { ID: 5, text: "Pineapples", image: "images/Pineapples.svg" }
- ];
- const value = fruits[0];
- function innerList_selectionChanged (e) {
- const dropDownBox = $("#dropDownBox").dxDropDownBox("instance");
- dropDownBox.option("value", e.addedItems[0]);
- dropDownBox.close();
- }
- </script>
- .custom-item {
- position: relative;
- min-height: 30px;
- }
- .custom-item > img {
- left: 1px;
- margin-top: 3px;
- max-height: 30px;
- width: auto;
- position: absolute;
- }
- .product-name {
- display: inline-block;
- padding-left: 45px;
- text-indent: 0;
- line-height: 30px;
- font-size: 15px;
- width: 100%;
- }
Feedback
Was this page helpful?
How can we improve this page?
Select one or more answers
Additional comments/thoughts:
If you have any questions, submit a ticket to our Support Center.