handsontable-key-value
handsontable-key-value copied to clipboard
Wrong value display when source exists 0 as the key
Describe the bug When setting source has item with key is 0 then display value of null and 0 is the display value of the item with key 0
Stackblitz https://stackblitz.com/edit/handsontable-key-value-demo-1xcp3d
You can see that item 1 and 2 both display value 'Ford' in column A, although brand of item 1 is null
My solution
Update function _getSourceItem
in handsontable-key-value/commonjs/common/getSourceItem.js
when value is null or undefined
function _getSourceItem(items, keyProperty, keyValue) {
return items.find(function(item) {
const key = item[keyProperty]
let castedKeyValue = keyValue
if (keyValue === null && key !== null) {
return false
}
if (keyValue === undefined && key !== undefined) {
return false
}
if (typeof castedKeyValue !== typeof key) {
if (typeof key === 'number') {
castedKeyValue = Number(keyValue)
} else if (typeof key === 'boolean') {
castedKeyValue = keyValue === 'true'
}
}
return key === castedKeyValue
})
}