jspreadsheet / ce

Jspreadsheet is a lightweight vanilla javascript plugin to create amazing web-based interactive tables and spreadsheets compatible with other spreadsheet software.
https://bossanova.uk/jspreadsheet/v4
MIT License
6.66k stars 820 forks source link

How to remove image from cell? #1634

Open flatsiedatsie opened 11 months ago

flatsiedatsie commented 11 months ago

I found it surprisingly difficult to remove an image from a cell.

For example, in the demo you can see that pressing backspace shows the image in a popup instead of removing it.

I resorted to hacking a "Clear cell" option into the context menu, but it would be better if backspace removed the image.

if (x) {

                        items.push({
                            title: 'Clear cell',
                            onclick:function() {
                                obj.updateCell(x, y, '', true);
                            }
                        });
flatsiedatsie commented 11 months ago

This modification makes the backspace work:

                                    } else if ((e.keyCode == 8) ||
                                               (e.keyCode >= 48 && e.keyCode <= 57) ||
                                               (e.keyCode >= 96 && e.keyCode <= 111) ||
                                               (e.keyCode >= 187 && e.keyCode <= 190) ||
                                               ((String.fromCharCode(e.keyCode) == e.key || String.fromCharCode(e.keyCode).toLowerCase() == e.key.toLowerCase()) && jexcel.validLetter(String.fromCharCode(e.keyCode)))) {

                                        if ((e.keyCode == 8) && jexcel.current.options.columns[columnId].type == 'image'){
                                            jexcel.current.updateCell(columnId, rowId, '', true);
                                        }

                                        // Start edition
                                        jexcel.current.openEditor(jexcel.current.records[rowId][columnId], true);