Skip to content

Wrong value display when source exists 0 as the key #6

Description

@InvinNO1

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
  })
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions