Default Toolbar and its Customization

SpreadSheet consists of two main parts: a toolbar with instruments panel and a stylized datatable.

The full structure of SpreadSheet can be presented as:

  • Toolbar:
    • File block
      • Sheets select
      • Import from Excel
      • Export to Excel
    • Undo/Redo block
      • Undo button
      • Redo button
    • Font block:
      • Font family select
      • Font size select
      • Font type buttons
      • Font color select
      • Background color select
      • Borders select
    • Align block:
      • Horizontal Align button
      • Vertical Align button
      • Text Wrap button
      • Merge button
    • Number block:
      • Number format select
      • Custom format button
    • Edit block:
      • Sort A to Z button
      • Sort Z to A button
      • Create filter button
      • Named range button
      • Conditional format button
      • Lock/unlock cell button
      • Add link button
      • Create dropdown button
      • Clear styles button
    • Insert block:
      • Image button
      • Graph button
    • View block:
      • Row button
      • Column button
      • Hide/show gridlines button
      • Hide/show headers button
      • Freeze/unfreeze rows button
      • Freeze/unfreeze columns button
  • DataTable

Toolbar

The toolbar contains a panel with instruments for editing and formatting the content of table's cells.

There are two modes of toolbar displaying: the "default" short one and the "full" one. In the default mode, toolbar is shown with a limited set of buttons.

To show all available buttons on the toolbar, you should specify the "full" mode, using the toolbar property:

webix.ui({
    view:"spreadsheet",
    data: base_data,
    toolbar: "full"
});

Related sample:  Toolbar with all buttons

To refer to the toolbar object, firstly you need to specify the toolbar's id in the toolbar configuration.

var bar = {
    view: "toolbar",
    css: "webix_ssheet_toolbar webix_layout_toolbar",
    id: "bar",
    elements: [{...}]
}

Then you can address to the toolbar via the corresponding id.

spreadsheet.$$("bar");

Toolbar buttons

In this section we will consider the blocks of buttons, the names that you can use to refer to them and the purpose of each block in detail.

File block

It includes the "sheet" select that allows working with sheet and contains three options:

  • "new-sheet" - for creating a new sheet
  • "copy-sheet" - for copying the sheet's content into a new sheet
  • "remove-sheet" - for removing a sheet

and two buttons:

  • "excel-import" button allows importing data from Excel
  • "excel-export" button lets export data into Excel

Undo/Redo block

It includes two buttons:

  • the "undo" button discards the recent change and reverts Spreadsheet into the previous state
  • the "redo" button restores the applied change one more time

Font block

This block contains a large group of buttons intended for handling font and cell borders' settings:

  • the "font-family" select allows choosing the necessary font for the cell's text
  • the "font-size" select sets the font size of the cell's text
  • the Font group of buttons helps to define the weight, style and decoration of the font:
    • "font-weight" button
    • "font-style" button
    • "text-decoration" button
  • the "color" select sets the font color
  • the "background" select sets the cell color
  • the "borders" select lets apply a new or different style for cell borders

Align block

Besides managing Horizontal and Vertical cell alignment, this block also includes means of text wrapping and merging cells' content:

  • the "text-align" select allows specifying one of three modes of text alignment in a cell: left, right or center
  • the "vertical-align" select defines the mode of vertical text alignment in a cell: top, middle or bottom
  • the "wrap" button lets wrap text in a cell
  • the "span" button allows merging the content of several cells and splitting it as well

Number block

This block contains the format select, which sets the format of cell content. The available formats are:

  • Common
  • Currency
  • Number
  • Percent

One more element of the block is the "custom-format" button which allows setting a custom format for a number in a cell.

Edit block

The block includes a set of buttons for editing the cell's content:

  • "sort-asc" and "sort-desc" buttons are used for sorting in ascending and descending directions
  • "create-filter" button sets a filter in a cell
  • "add-range" button sets a named range of cells for using it further in math formulas
  • "conditional-format" button allows specifying a particular style for a cell, depending on a certain condition
  • "lock-cell" button blocks/allows editing of the cell's value
  • "add-link" button sets a link in a cell
  • "add-dropdown" button creates an editor with options in a cell
  • "clear-styles" button removes all the styles formatting in SpreadSheet

Insert block

  • "add-image" button adds an image into a cell
  • "add-sparkline" button inserts a sparkline in a cell

View block

  • "row" button allows manipulating rows:insert/delete/hide/show them
  • "column" button lets manipulating columns:insert/delete/hide/show them
  • "hide-gridlines" button hides/shows gridlines of the Spreadsheet
  • "hide-headers" button hides/shows headers of rows and columns
  • "freeze-rows" button freezes/unfreezes rows
  • "freeze-columns" button freezes/unfreezes columns

Customizing toolbar's buttons

Settings for the default toolbar are specified in the buttons configuration object. It contains the names of button blocks as parameters. The parameters' values are arrays of buttons that are included into this or that block.

buttons: {
    "undo": ["undo","redo"],
    "font": ["font-family","font-size","font-weight","font-style",
    "text-decoration","color","background","borders"],
    "align": ["text-align","vertical-align","wrap","span"],
    "format": ["format"]
}

The button blocks' names correspond to the properties defined in the localization files that specify the language of its labels. The default toolbar specified through the buttons configuration object has just one level.

If you want to create a two-level toolbar with more buttons or to customize the "full" toolbar with the full set of buttons, you should follow the instructions described in the Customizing the "toolbar" collection section of the User Interface Guidelines chapter.

Removing a block or a button

In case you want to remove some block or button specified in the default configuration, you need just not to define them in the buttons object.

Adding a custom block or a button

To add your own block of buttons into the toolbar, you should specify its name as a property in the "buttons" configuration. The value of this property is an array of buttons.

To add a custom button, you should specify its name in the array of buttons of the corresponding block.

If you don't want to show the block's name, add the "$" sign before the block's name.

 buttons: {
    "$title": [{
        view: "label", width: 150, label: "My SpreadSheet"
    }],
    "undo": ["undo","redo"],
    "text": ["font-weight","font-style","text-decoration","color"],
    "My Block": [{
        view: "button", name: "my-button", width: 100, label: "My Button",
        tooltip: "Click this button", click: function(){webix.message("Click")}
    }]
 }

Related sample:  Toolbar buttons

Customizing Datatable

The datatable part of SpreadSheet features the same functionality that the Datatable widget does. So, you can customize the datatable in SpreadSheet in various ways.

You can refer to the datatable object as follows:

spreadsheet.$$("cells");

For example, you can attach a context menu with some actions for datatable cells and call the handler function on the right click.

webix.ready(function(){
    webix.ui({
        view:"spreadsheet", 
        id:"ss",                
        math:true,      
        data:base_data
    });         
 
    webix.ui({
        view:"contextmenu",
        data:["Cut", "Copy", "Paste", "Delete"],
        click:function(id, event){
            var cell = this.getContext().id;
            webix.message(id+" on row "+cell.row+" of the column "+cell.column);                            
    }).attachTo( $$("ss").$$("cells"));         
});

Related sample:  Custom menu

Back to top