* Returns single value from the data array. * * @param {number} row Visual row index. * @param {number} prop The column property. * @returns {*}
(row: number, prop: string | number)
| 811 | * @returns {*} |
| 812 | */ |
| 813 | get(row: number, prop: string | number) { |
| 814 | const physicalRow = this.hot!.toPhysicalRow(row); |
| 815 | |
| 816 | let dataRow: Record<string | number, unknown> = this.dataSource![physicalRow] as Record<string | number, unknown>; |
| 817 | // TODO: To remove, use 'modifyData' hook instead (see below) |
| 818 | const modifiedRowData = this.hot!.runHooks('modifyRowData', physicalRow); |
| 819 | |
| 820 | dataRow = typeof modifiedRowData !== 'number' ? modifiedRowData as Record<string | number, unknown> : dataRow; |
| 821 | // |
| 822 | |
| 823 | const { dataDotNotation } = this.hot!.getSettings(); |
| 824 | let value: unknown = null; |
| 825 | |
| 826 | // try to get value under property `prop` (includes dot) |
| 827 | if (dataRow && hasOwnProperty(dataRow, prop)) { |
| 828 | value = dataRow[prop]; |
| 829 | |
| 830 | } else if (dataDotNotation && typeof prop === 'string' && prop.indexOf('.') > -1) { |
| 831 | let out: Record<string, unknown> = dataRow; |
| 832 | |
| 833 | if (!out) { |
| 834 | return null; |
| 835 | } |
| 836 | |
| 837 | const sliced = prop.split('.'); |
| 838 | |
| 839 | for (let i = 0, ilen = sliced.length; i < ilen; i++) { |
| 840 | out = out[sliced[i]] as Record<string, unknown>; |
| 841 | |
| 842 | if (typeof out === 'undefined') { |
| 843 | return null; |
| 844 | } |
| 845 | } |
| 846 | |
| 847 | value = out; |
| 848 | |
| 849 | } else if (typeof prop === 'function') { |
| 850 | value = (prop as (row: unknown) => unknown)(this.dataSource!.slice(physicalRow, physicalRow + 1)[0]); |
| 851 | } |
| 852 | |
| 853 | const visualColumnIndex = this.propToCol(prop); |
| 854 | const physicalColumn = typeof visualColumnIndex === 'number' |
| 855 | ? this.hot!.toPhysicalColumn(visualColumnIndex) |
| 856 | : null; |
| 857 | |
| 858 | if (isUnsignedNumber(physicalRow) && isUnsignedNumber(physicalColumn)) { |
| 859 | value = getValueGetterValue( |
| 860 | value, |
| 861 | this.metaManager!.getCellMeta(physicalRow, physicalColumn, { |
| 862 | visualRow: row, |
| 863 | visualColumn: visualColumnIndex, |
| 864 | skipMetaExtension: true |
| 865 | }) |
| 866 | ); |
| 867 | } |
| 868 | |
| 869 | if (this.hot!.hasHook('modifyData')) { |
| 870 | const valueHolder = createObjectPropListener(value); |