SpreadsheetColumn (extends TableColumn)

The configuration class for Spreadsheeet columns

Syntax

Spreadsheet.columnTypeRegistry.foo = class FooColumn extends SpreadsheetColumn {
    ...
}
new Table({
    data: [...]
    columns: [{ type: 'number' }]
})

Options

types description arguments default
type String

Declares which column class from Table.columnTypeRegistry to use. Optional, default is TableColumn

frozen Boolean

Make column stay in place when table body scrolls

class String

classes to append to header and cells (space separated)

render Function

Render method for the cell

record:Object, cell:Element, columnConfiguration:Object, table:Table
header Function, String

Render method for the header

columnConfiguration:Object, table:Table
width String

Valid value for css grid template (i.e. px, percent, min-content...)

splitInto Function, String

split cell into multiple rows by the resulting of this method. Expected return is iterable (specifically responds to .map).

record:Object
headerEditable Boolean

allow header to be changed, fires events when changed

true
SOURCE CODE
import SpreadsheetCell from './cell.js';
import HeaderCell from './header-cell.js';
import TableColumn from '../table/column.js';
import Input from '../input.js';
import { result } from '../../support';

class SpreadsheetColumn extends TableColumn {
    static Cell = SpreadsheetCell;
    static HeaderCell = HeaderCell;
    
    static assignableAttributes = {
        type: null,
        attribute: null,
        headerEditable: true
    }
    
    static assignableMethods = [
        'input', 'copy', 'paste'
    ]
    
    initialize (configs) {
        this.configuredContextMenu = configs.contextMenu
        this.inputOptions = configs.input
    }

    headerFallback () {
        return this.attribute
    }
    
    render (record) {
        const value = result(record, this.attribute)
        if (value && typeof value == 'string') {
            return value.replaceAll("\n", "<br>")
        }
        return value
    }
    
    copy (cell) {
        return result(cell.record, this.attribute)
    }
    
    static pasteAccepts = ["text/plain"]
    paste (cell, value) {
        cell.record[this.attribute] = value
    }
    
    clear (cell) {
        cell.record[this.attribute] = null
    }
    
    input (record, cell, options) {
        return Input.create(this.type || 'contentarea', Object.assign({
            record: record,
            attribute: this.attribute
        }, this.inputOptions, options))
    }
    contextMenu (menu, ...args) {
        if (this.configuredContextMenu) {
            return this.configuredContextMenu(menu, ...args)
        } else {
            return menu
        }
    }
}