Spreadsheet toolbars

Jexcel brings the basic options in the default toolbar, but it would be also possible to customize that options as shown in the following examples.


Default toolbar

The following example shows how to enable the default toolbar in the worksheet.

NOTE: Material icons style sheet is mandatory for the toolbar usage.


It is also possible to show or hide the custom toolbar using JavaScript.




Source code

<html>
<script src="https://jexcel.net/v7/jexcel.js"></script>
<script src="https://jexcel.net/v7/jsuites.js"></script>
<link rel="stylesheet" href="https://jexcel.net/v7/jexcel.css" type="text/css" />
<link rel="stylesheet" href="https://jexcel.net/v7/jsuites.css" type="text/css" />

<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Material+Icons" />

<div id="spreadsheet1"></div>

<script>
var grid = jexcel(document.getElementById('spreadsheet1'), {
    minDimensions: [15,5],
    toolbar: true,
    allowComments: true,
    license: 'YjQzMzdlOTRiOGY3ZTQ0ZDQ4ZTI1YWU3MDFjMDI0ZWJmOTNjODA1NWFiZTRiNDJhNmRiYTJlZjkwODQ3N2IwMWRmNWRjYWUwZDViM2VhMmI3NzVjOTcwMzVlN2ZhODI1Y2EyMmE3NDI0ZmE0ZjVmNGQ2MWEzN2M3MTA4MThhMDUsZXlKdVlXMWxJam9pY0dGMWJDNW9iMlJsYkNJc0ltUmhkR1VpT2pFMk16SXdPVEkwTURBc0ltUnZiV0ZwYmlJNld5SnFjMlpwWkdSc1pTNXVaWFFpTENKcVpYaGpaV3d1Ym1WMElpd2lZMjlrWlhOaGJtUmliM2d1YVc4aUxDSnFjMmhsYkd3dWJtVjBJaXdpTVROemQyMHVZM05pTG1Gd2NDSXNJbXh2WTJGc2FHOXpkQ0pkTENKd2JHRnVJam9pTXlKOQ==',
});
</script>

<input type='button' value='Show Toolbar' onclick="grid.showToolbar();">
<input type='button' value='Hide Toolbar' onclick="grid.hideToolbar();">
</html>


Customized toolbar

It is possible to customize the toolbar using the initialization property toolbar as below.



Source code

<html>
<script src="https://jexcel.net/v7/jexcel.js"></script>
<script src="https://jexcel.net/v7/jsuites.js"></script>
<link rel="stylesheet" href="https://jexcel.net/v7/jexcel.css" type="text/css" />
<link rel="stylesheet" href="https://jexcel.net/v7/jsuites.css" type="text/css" />

<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Material+Icons" />

<div id="spreadsheet2"></div>

<script>
var data2 = [
    ['Canada', 'Cheese', 1],
    ['Japan', 'Apples', 0],
    ['United States', 'Carrots', 1],
    ['China', 'Oranges', 0],
];

var customToolbar = [
    {
        content: 'save',
        onclick: function () {
            table.download();
        }
    },
    {
        type:'divisor',
    },
    {
        type:'select',
        width: '160px',
        options: [ 'Verdana', 'Arial', 'Courier New' ],
        render: function(e) {
            return '<span style="font-family:' + e + '">' + e + '</span>';
        },
        onchange: function(a,b,c,d) {
            table.setStyle(table.getSelected(), 'font-family', d);
        }
    },
    {
        type: 'select',
        width: '50px',
        options: ['format_align_left','format_align_center','format_align_right','format_align_justify'],
        render: function(e) {
            return '<i class="material-icons">' + e + '</i>';
        },
        onchange: function(a,b,c,d) {
            if (d == 'format_align_left') {
                table.setStyle(table.getSelected(), 'text-align', 'left');
            } else if (d == 'format_align_center') {
                table.setStyle(table.getSelected(), 'text-align', 'center');
            } else if (d == 'format_align_right') {
                table.setStyle(table.getSelected(), 'text-align', 'right');
            } else if (d == 'format_align_justify') {
                table.setStyle(table.getSelected(), 'text-align', 'justify');
            }
        }
    },
    {
        type: 'i',
        content: 'format_bold',
        onclick: function(a,b,c) {
            table.setStyle(table.getSelected(), 'font-weight', 'bold');
        }
    },
    {
        type: 'i',
        content: 'format_color_text',
        onclick: function(element, instance, item) {
            if (! item.color) {
                var colorPicker = jSuites.color(item, {
                    onchange:function(o, v) {
                        table.setStyle(table.getSelected(), 'color', v);
                    }
                });
                colorPicker.open();
            }
        }
    },
    {
        type: 'i',
        content: 'format_color_fill',
        onclick: function(element, instance, item) {
            if (! item.color) {
                var colorPicker = jSuites.color(item, {
                    onchange:function(o, v) {
                        table.setStyle(table.getSelected(), 'background-color', v);
                    }
                });
                colorPicker.open();
            }
        }
    }
];

var table = jexcel(document.getElementById('spreadsheet2'), {
    data: data2,
    columns: [
        {
            title: 'Country',
            type: 'autocomplete',
            source: ['Brazil','Canada','China','Japan','United States','United Kingdom'],
            width: '300px',
        },
        {
            title: 'Food',
            type: 'dropdown',
            source:['Apples','Bananas','Carrots','Oranges','Cheese'],
            width: '150px',
        },
        {
            title: 'Stock',
            type: 'checkbox',
            width: '100px',
        },
    ],
    toolbar: customToolbar,
    license: 'YjQzMzdlOTRiOGY3ZTQ0ZDQ4ZTI1YWU3MDFjMDI0ZWJmOTNjODA1NWFiZTRiNDJhNmRiYTJlZjkwODQ3N2IwMWRmNWRjYWUwZDViM2VhMmI3NzVjOTcwMzVlN2ZhODI1Y2EyMmE3NDI0ZmE0ZjVmNGQ2MWEzN2M3MTA4MThhMDUsZXlKdVlXMWxJam9pY0dGMWJDNW9iMlJsYkNJc0ltUmhkR1VpT2pFMk16SXdPVEkwTURBc0ltUnZiV0ZwYmlJNld5SnFjMlpwWkdSc1pTNXVaWFFpTENKcVpYaGpaV3d1Ym1WMElpd2lZMjlrWlhOaGJtUmliM2d1YVc4aUxDSnFjMmhsYkd3dWJtVjBJaXdpTVROemQyMHVZM05pTG1Gd2NDSXNJbXh2WTJGc2FHOXpkQ0pkTENKd2JHRnVJam9pTXlKOQ==',
});
</script>
</html>


Toolbar options

The following options define how Jexcel Spreadsheet would render its toolbar.

NOTE: Same of the properties below are only available from jSuites v3.5.1+

PropertyDescription
type: stringElement type: i | icon | divisor | label | select | color
content: stringElement content, could be a text string or the icon (from material icons) when you use type: icon; click here for all possible keys
title: booleanTooltip for the toolbar element
width: numberToolbar element width
state: booleanAdd state controller to the toolbar element
active: booleanInitial state for the toolbar element
class: stringCSS Class for each toolbar element
optionsWhen type is select, this option would define the items of the dropdown.
value: numberThe initial selected option for the type: select
render: methodParse the items of type: select.
onclick: methodWhen a item is clicked
onchange: methodFor the type select when a new item is selected
k: string (deprected)means the style should be apply to the cell;
v: string (deprected)means the value of the style should be apply to the cell; When type:select, you can define an array of possibles values;

More about the jSuites toolbar