Created
October 3, 2019 09:46
-
-
Save davestewart/671b5a8715868b5491345639ff68c756 to your computer and use it in GitHub Desktop.
Handsontable hooks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cells (row, col, name) { | |
if (!this.hot) { | |
return null | |
} | |
const rowData = this.hot.getSourceDataAtRow(row) | |
if (rowData) { | |
if (rowData.state === NegotiationItemState.removed) { | |
return { readOnly: true } | |
} | |
} | |
}, | |
afterRenderer (td, row, col, prop, value, column) { | |
if (!this.hot) { | |
return | |
} | |
// if invalid, add row and prop to cell so tippy can render | |
if (column.valid === false) { | |
td.setAttribute('row', row) | |
td.setAttribute('prop', prop) | |
} | |
// otherwise, destroy tippy instance on cell if it exists | |
else { | |
if (td._tippy) { | |
td._tippy.destroy() | |
} | |
} | |
// styles | |
// row data (from table instance data property) | |
const rowData = this.hot.getSourceDataAtRow(row) | |
// html class to be returned at end of function | |
let className = '' | |
// add classes based on columns setting | |
if (column) { | |
// user-supplied class name | |
className += ' ' + (column.className || '') | |
// read only column | |
if (!column.editor) { // column.readOnly || | |
className += ' htReadOnly' | |
} | |
} | |
// cell was edited | |
const edited = this.changes.get(row, column.data) | |
if (edited) { | |
className += ' htEdited' | |
} | |
// add classes based on source data | |
if (rowData) { | |
// properties were updated | |
if (Array.isArray(rowData.propertiesUpdated) && rowData.propertiesUpdated.includes(prop)) { | |
className += ' htUpdated' | |
} | |
// quantity | |
if (rowData.type === 'loan' && rowData.quantity === 0) { | |
const colQuantity = this.settings.columns.find(col => col.data === 'quantity' || col.data === 'quantityRequired') | |
if (colQuantity) { // && !colQuantity.allowEmpty // custom `Quantity` column setting | |
className += ' htRemove' | |
} | |
} | |
if (rowData.type === 'loan') { | |
// console.log(column, rowData) | |
} | |
// removing | |
if (rowData.remove) { | |
className += ' htRemove' | |
} | |
// removed | |
if (rowData.state === NegotiationItemState.removed) { | |
className += ' htRemoved' | |
} | |
} | |
// return new meta data | |
td.className += className + ' ' | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment