Editors

Jexcel input editors is a powerful feature and help users to input data into cells. It is possible to integrate rich and responsive web components to improve the user experience. There are several native editors available such as text, numeric, hidden, dropdown, checkbox, radio, calendar, image, color, email URL, progress bar, rating, auto number, rich text, percent and notes.

The following template would make it possible to go beyond the native editors. Using the template developers would be able to integrate any JavaScript plugin and create a custom data input tool on any Jexcel spreadsheet.

Basic editor template

var clockEditor = function() {
    var methods = {};

    methods.createCell = function(cell, value, x, y, instance, options) {
        cell.innerHTML = value;
    }

    methods.updateCell = function(cell, value, x, y, instance, options) {
        if (cell) {
            cell.innerHTML = value;
        }
    }

    methods.openEditor = function(cell, value, x, y, instance, options) {
        // Create input from the helpers
        var editor = jexcel.helpers.createEditor('input', cell);
        editor.value = value;
        // Instance of the clock picker
        $(editor).clockpicker({
            afterHide:function() {
                setTimeout(function() {
                    // To avoid double call
                    if (cell.children[0]) {
                        instance.closeEditor(cell, true);
                    }
                });
            }
        });
        editor.focus();
    }

    methods.closeEditor = function(cell, save) {
        if (save) {
            cell.innerHTML = cell.children[0].value;
        } else {
            cell.innerHTML  = '';
        }

        return cell.innerHTML;
    }

    return methods;
}();

Using a custom editor

Considering the custom clockEditor above, the property type can be used to define the custom editor.

var data = [
    ['PHP', '14:00'],
    ['Javascript', '16:30'],
];

jexcel(document.getElementById('spreadsheet'), {
    data: data,
    columns: [
        {
            type: 'text',
            title: 'Course Title',
            width: '300px'
        },
        {
            type: clockEditor,
            title: 'Time',
            width: '200px'
        },
     ],
     license: '39130-64ebc-bd98e-26bc4',
});

Append the new editor object to the jexcel controllers

To include a custom editor in the Jexcel distribution. You can use the following syntax.

// Append the new editor to the jexcel editor controllers
jexcel.editors.clock = clockEditor;

// After that the usabe can called using a string
var data = [
    ['PHP', '14:00'],
    ['Javascript', '16:30'],
];

jexcel(document.getElementById('spreadsheet'), {
    data: data,
    columns: [
        { type: 'text', width: '300px' },
        { type: 'clock', width: '200px' },
     ],
     license: '39130-64ebc-bd98e-26bc4',
});

Editors in a cell level

Using the initialization property cells is possible to overwrite the column definitions to a cell level.

<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" />

<div id="spreadsheet"></div>

<script>
var data = [
    ['<img src="https://www.autoblog.com/img/research/styles/photos/performance.jpg" style="width:200px;height:auto;"><br><h3>Vehicle Payment Calculator</h3>', ''],
    ['Purchase price', '19700'],
    ['Down payment', '1000'],
    ['Trade-in value', '500'],
    ['Interest rate', '0.0305'],
    ['Length of loan (in months)', '60'],
    ['', ''],
    ['Monthly payment', '=PMT(B5/12,B6,B2-(B3+B4))'],
    ['Total cost', '=-(B8*B6)+(B3+B4)'],
];

jexcel(document.getElementById('spreadsheet'), {
    data: data,
    columns: [
        { width:'300px' },
        { width:'200px' },
    ],
    mergeCells: {
        A1: [2, 1]
    },
    rows: {
        0: { height:'200px' }
    },
    cells: {
        A1: { type:'html' },
        B2: { type:'text', mask:'$ #,##.00', decimal:'.' },
        B3: { type:'text', mask:'$ #,##.00', decimal:'.' },
        B4: { type:'text', mask:'$ #,##.00', decimal:'.' },
        B5: { type:'percent' },
        B8: { type:'text', mask:'[-]$ #,##.00', disabledMaskOnEdition: true, decimal:'.' },
        B9: { type:'text', mask:'[-]$ #,##.00', disabledMaskOnEdition: true, decimal:'.' },
    },
    license: 'YjQzMzdlOTRiOGY3ZTQ0ZDQ4ZTI1YWU3MDFjMDI0ZWJmOTNjODA1NWFiZTRiNDJhNmRiYTJlZjkwODQ3N2IwMWRmNWRjYWUwZDViM2VhMmI3NzVjOTcwMzVlN2ZhODI1Y2EyMmE3NDI0ZmE0ZjVmNGQ2MWEzN2M3MTA4MThhMDUsZXlKdVlXMWxJam9pY0dGMWJDNW9iMlJsYkNJc0ltUmhkR1VpT2pFMk16SXdPVEkwTURBc0ltUnZiV0ZwYmlJNld5SnFjMlpwWkdSc1pTNXVaWFFpTENKcVpYaGpaV3d1Ym1WMElpd2lZMjlrWlhOaGJtUmliM2d1YVc4aUxDSnFjMmhsYkd3dWJtVjBJaXdpTVROemQyMHVZM05pTG1Gd2NDSXNJbXh2WTJGc2FHOXpkQ0pkTENKd2JHRnVJam9pTXlKOQ==',
});
</script>
</html>