You can add a dropdown menu at the top of the SpreadSheet. It allows saving space on the toolbar, moving some of its commands to the menu.
To add a default menu, set the menu property to true
.
webix.ui({
view:"spreadsheet",
data: math_data_simple,
menu: true
});
The default menu has the same structure as the full toolbar.
Settings for the default menu are specified in the menu configuration array. This array contains objects, each representing a single block of the menu. These objects have the id property with the name of the block, and the submenu property with the array of objects representing menu options. Each object in submenu can also have the id with the name of the block or option and (optionally) submenu. Check the example below:
const menu = [
{ id: "file", submenu: [
{ id: "sheet", submenu: [
{ id: "new-sheet" },
{ id: "copy-sheet" },
{ id: "remove-sheet" },
{ id: "hide-sheet" }
]}
]},
{ id: "undo-redo", submenu: [
{ id: "undo" },
{ id: "redo" }
]}
]
This section provides a detailed description of each block of Menu options. There are the following menu blocks:
This block includes a set of options for manipulations with sheets:
webix.ui({
view: "spreadsheet",
data: base_data,
menu: [
{ id: "file", submenu: [
{ id: "sheet", submenu: [
{ id: "new-sheet" },
{ id: "copy-sheet" },
{ id: "remove-sheet" },
{ id: "hide-sheet" }
]},
{ id: "excel-import" },
{ id: "excel-export" },
{ id: "print" },
{ id: "print-borders" }
]}
]
});
This block includes the following options:
webix.ui({
view: "spreadsheet",
data: base_data,
menu: [
{ id: "undo-redo", submenu: [
{ id: "undo" },
{ id: "redo" }
]}
]
});
This block contains options for setting fonts and text format of the cell's content:
webix.ui({
view: "spreadsheet",
data: base_data,
menu: [
{ id: "font", submenu: [
{ id: "font-family", submenu:[
{ id: "Arial", value: "Arial" },
{ id: "'Roboto', sans-serif", value: "Roboto" },
{ id: "'PT Sans', Tahoma", value: "PT Sans" },
{ id: "'Open Sans', sans-serif", value: "Open Sans" },
{ id: "Tahoma", value: "Tahoma" },
{ id: "Verdana", value: "Verdana" },
{ id: "Calibri, Tahoma", value: "Calibri" },
]},
{ id: "font-size", submenu: [
{ id: "8px", value: "8" },
{ id: "9px", value: "9" },
{ id: "10px", value: "10" },
{ id: "11px", value: "11" },
{ id: "12px", value: "12" },
{ id: "14px", value: "14" },
{ id: "15px", value: "15" },
{ id: "16px", value: "16" },
{ id: "18px", value: "18" },
{ id: "20px", value: "20" },
{ id: "22px", value: "22" },
{ id: "24px", value: "24" },
{ id: "28px", value: "28" },
{ id: "36px", value: "36" },
]},
{ id: "font-weight" },
{ id: "font-style" },
{ id: "underline" },
{ id: "strike" }
]}
]
});
This block includes options for horizontal and vertical cell alignment, merging cells' content, the means of text wrapping, as well as indenting text in a cell to the left or to the right:
webix.ui({
view:"spreadsheet",
data: base_data,
menu: [
{ id: "align", submenu: [
{ id: "text-align", submenu: [
{ id: "left" },
{ id: "center" },
{ id: "right" }
]},
{ id: "vertical-align", submenu: [
{ id: "top" },
{ id: "middle" },
{ id: "bottom" }
]},
{ id: "span" },
{ id: "wrap"},
{ id: "increase-indent"},
{ id: "decrease-indent"}
]}
]
});
This block contains the following options:
webix.ui({
view:"spreadsheet",
data: base_data,
menu: [
{ id: "number", submenu: [
{ id: "format", submenu: [
{ id: "common" },
{ id: "price" },
{ id: "int" },
{ id: "percent" },
{ id: "date" },
{ id: "string" },
{ id: "custom" }
]},
{ id: "increase-decimals" },
{ id: "decrease-decimals" },
]}
]
});
This block includes a set of options for editing the cell's content:
view: "spreadsheet",
menu: [
{ id: "edit", submenu: [
{ id: "sort", submenu: [
{ id: "sort-asc" },
{ id: "sort-desc" }
]},
{ id: "create-filter" },
{ id: "add-range" },
{ id: "conditional-format" },
{ id: "lock-cell" },
{ id: "add-link" },
{ id: "add-dropdown" },
{ id: "clear", submenu: [
{ id: "clear-value" },
{ id: "clear-style" },
{ id: "clear-conditional-formats" },
{ id: "clear-dropdown-editors" },
{ id: "clear-filters" },
{ id: "clear-comments" },
{ $template: "Separator" },
{ id: "clear-all" }
]},
{ id: "validation", submenu: [
{ id: "add-cell-validation" },
{ id: "remove-cell-validation" },
{ id: "highlight-invalid-data" },
{ id: "remove-highlight-invalid-data" }
]},
{ id: "find" }
]}
]
This block includes a set of options for additional content, which can be attached to cells:
view: "spreadsheet",
menu: [
{ id: "insert", submenu: [
{ id: "image", submenu: [
{ id: "add-image-cell" },
{ id: "add-image-top" }
]},
{ id: "graph", submenu: [
{ id: "add-sparkline" },
{ id: "add-chart" }
]},
{ id: "add-comment" },
{ id: "controls", submenu: [
{ id: "add-checkbox" },
{ id: "add-radio" }
]}
]}
]
This block includes the following options:
view: "spreadsheet",
menu: [
{ id: "view", submenu: [
{ id: "column", submenu: [
{ id: "add-column" },
{ id: "del-column" },
{ id: "show-column" },
{ id: "hide-column" },
{ id: "resize-column" },
{ id: "format-column", submenu:[
{ id: "common-column" },
{ id: "price-column" },
{ id: "int-column" },
{ id: "percent-column" },
{ id: "date-column" },
{ id: "string-column" },
{ id: "custom-column" }
]}
]},
{ id: "row", submenu: [
{ id: "add-row" },
{ id: "del-row" },
{ id: "show-row" },
{ id: "hide-row" },
{ id: "resize-row" },
{ id: "format-row", submenu:[
{ id: "common-row" },
{ id: "price-row" },
{ id: "int-row" },
{ id: "percent-row" },
{ id: "date-row" },
{ id: "string-row" },
{ id: "custom-row" }
]}
]},
{ id: "freeze-columns" },
{ id: "freeze-rows" },
{ id: "hide-gridlines" },
{ id: "hide-headers" },
{ id: "show-formulas" }
]}
]
Note that all available default options are already added to the menu. You can only delete or reorder them.
You can change the top menu in two ways: by setting the menu property as an array of options or by changing this array in the onViewInit handler.
In case you want to remove some blocks or options from the default configuration, set the menu array without them.
To add custom option/block into the menu, you should specify it as a value of the id property, and its label as a value of the value property.
There are two ways to add a label to a custom option/block:
If you are using locale, key would be the value of the id property of your option and value would be the label:
webix.i18n.spreadsheet.menus["new-option"] = "New option";
Then you can add your option to the menu array during SpreadSheet configuration:
menu: [{ id: "new-option" }]
Another way to add a label is to set the value property directly at the menu array while also setting the id property of your option:
menu: [{ id: "new-option", value: "New option" }]
Note that this method won't allow localization.
To define the action that will be triggered when your option is selected, you should attach a handler to Spreadsheet onCommand event:
webix.ready(function(){
webix.ui({
view: "spreadsheet",
data: base_data,
menu: [{ id: "new-option", value: "My option" }],
on: {
onCommand(obj) {
if (obj.id === "new-option")
webix.message("click on custom option");
}
}
});
});
If you want to add an option from the existing list of commands, specify it as a value of the id property of the corresponding object in the submenu array:
{
id: "my-options",
value: "My Options",
submenu: [
{ id: "excel-import" },
{ id: "new-sheet" }
]
}
You can also use the onViewInit event to add or remove custom blocks and options of the default menu. For example, this is how you can add an option:
webix.ui({
view: "spreadsheet",
menu: true,
on: {
onViewInit(view, config){
if (view == "menu"){
config.data.push({ id: "new-option", value: "New option" });
}
}
}
});
Back to top