Back to Devexpress

RibbonSelectBoxItem Class

aspnetcore-js-devexpress-dot-richedit-9d40420e.md

latest7.5 KB
Original Source

RibbonSelectBoxItem Class

A ribbon select box item.

Declaration

ts
export class RibbonSelectBoxItem extends RibbonItemBase

Remarks

javascript
var commandId = "mySelectBox";
var ribbonSelectBox = new DevExpress.RichEdit.RibbonSelectBoxItem(
    commandId,
    new DevExpress.data.ArrayStore({ data: products, key: "ID" }),
    {
        beginGroup: true,
        width: 150,
        displayExpr: "Name",
        valueExpr: "ID",
    });

var options = DevExpress.RichEdit.createOptions();
options.ribbon.getTab(DevExpress.RichEdit.RibbonTabType.Home).insertItem(ribbonSelectBox, 3);
options.events.customCommandExecuted.addHandler(function(s, e) {
  switch (e.commandName) {
    case commandId:
      console.log(e.parameter);
    }
});
javascript
var products = [{
    "ID": 1,
    "Name": "HD Video Player",
}, {
    "ID": 2,
    "Name": "SuperHD Player",
}, {
    "ID": 3,
    "Name": "SuperPlasma 50",
}, {
    "ID": 4,
    "Name": "SuperLED 50",
}, {
    "ID": 5,
    "Name": "SuperLED 42",
}, {
    "ID": 6,
    "Name": "SuperLCD 55",
}];

Inherited Members

beginGroup

id

Inheritance

RibbonItemBase RibbonSelectBoxItem

See Also

Ribbon Customization

constructor(id, dataSource)

Initializes a new instance of the RibbonSelectBoxItem class with specified settings.

Declaration

ts
constructor(
    id: RibbonItemId,
    dataSource: any[] | any,
    options?: RibbonSelectBoxItemOptions
)

Parameters

NameTypeDescription
idRibbonItemId

The item identifier.

| | dataSource | any |

The data source.

| | options | RibbonSelectBoxItemOptions |

The item options.

|

Properties

acceptCustomValue Property

Specifies whether the item accepts custom values.

Declaration

ts
acceptCustomValue?: boolean

Property Value

TypeDescription
boolean

true to accept custom values; otherwise, false.

|

Remarks

Set the acceptCustomValue property to true to allow a user to add new values to the select box. Note that in this case, you should implement the onCustomItemCreating handler to create a new data source entry.

javascript
var years = [2018, 2019, 2020];
var postfix = ' year';
var createItem = function(year) {
    return { text: year.toString() + postfix, value: year};
};
var dataSource = years.map(createItem);

richEdit.updateRibbon(function(ribbon) {
    ribbon.getTab(0).insertItem(new DevExpress.RichEdit.RibbonSelectBoxItem(
        'CustomDateSelectId', dataSource, {
        displayExpr: "text",
        valueExpr: "value",
        acceptCustomValue: true,
        onCustomItemCreating: function (e) {
            if (!e.customItem) {
                var item = createItem(parseInt(e.text));
                e.customItem = item;
                dataSource.push(item);
            }
        }
    }));
});
richEdit.events.customCommandExecuted.addHandler(function(s, e) {
    console.log(e);
});

dataSource Property

Binds the select box to a data source.

Declaration

ts
dataSource: any[]

Property Value

TypeDescription
any[]

The data source.

|

displayExpr Property

Specifies the data field whose values should be displayed.

Declaration

ts
displayExpr?: string

Property Value

TypeDescription
string

The name of the data field.

|

onCustomItemCreating Property

Specifies a function that is executed when a user adds a custom item.

Declaration

ts
onCustomItemCreating?: any

Property Value

TypeDescription
any

A function that creates a new data source entry.

|

Remarks

When the acceptCustomValue property is set to true , a user is allowed to add new values to the select box. Write the onCustomItemCreating function code to create a new data source entry.

javascript
var years = [2018, 2019, 2020];
var postfix = ' year';
var createItem = function(year) {
    return { text: year.toString() + postfix, value: year};
};
var dataSource = years.map(createItem);

richEdit.updateRibbon(function(ribbon) {
    ribbon.getTab(0).insertItem(new DevExpress.RichEdit.RibbonSelectBoxItem(
        'CustomDateSelectId', dataSource, {
        displayExpr: "text",
        valueExpr: "value",
        acceptCustomValue: true,
        onCustomItemCreating: function (e) {
            if (!e.customItem) {
                var item = createItem(parseInt(e.text));
                e.customItem = item;
                dataSource.push(item);
            }
        }
    }));
});
richEdit.events.customCommandExecuted.addHandler(function(s, e) {
    console.log(e);
});

placeholder Property

Specifies the text displayed by the item when its value is empty.

Declaration

ts
placeholder?: string

Property Value

TypeDescription
string

The placeholder text.

|

showClearButton Property

Specifies whether to display the Clear button in the item.

Declaration

ts
showClearButton: boolean

Property Value

TypeDescription
boolean

true to display the Clear button; otherwise, false.

|

textOptions Property

Specifies options of the text displayed next to the item.

Declaration

ts
textOptions: RibbonItemTextOptions

Property Value

TypeDescription
RibbonItemTextOptions

An object that contains text options.

|

type Property

Returns the item’s type.

Declaration

ts
readonly type = RibbonItemType.SelectBox

Property Value

TypeDescription
SelectBox

Identifies the SelectBox item type.

|

value Property

Specifies the currently selected value.

Declaration

ts
value?: any

Property Value

TypeDescription
any

The currently selected value.

|

valueExpr Property

Specifies the data field that provides values for the editor items.

Declaration

ts
valueExpr?: string

Property Value

TypeDescription
string

The name of the data field.

|

valueType Property

Specifies the data type of the selected value.

Declaration

ts
valueType?: string

Property Value

TypeDescription
string

The selected value type.

|

width Property

Specifies the item width.

Declaration

ts
width?: any

Property Value

TypeDescription
any

The item width.

|