Skip to content

Commit

Permalink
Added extra comments in code for changes #7031
Browse files Browse the repository at this point in the history
  • Loading branch information
wszymanski committed Jul 21, 2020
1 parent 411584e commit 156d454
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
10 changes: 8 additions & 2 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,7 @@ export default function Core(rootElement, userSettings, rootInstanceSymbol = fal
} else {
const [row, prop, , newValue] = changes[i];
const propToColResult = datamap.propToCol(prop);
// Populated data may contain indexes beyond current table boundaries.
const col = propToColResult !== null ? propToColResult : prop;
const cellProperties = instance.getCellMeta(row, col);

Expand Down Expand Up @@ -1188,7 +1189,8 @@ export default function Core(rootElement, userSettings, rootInstanceSymbol = fal

while (column > instance.countCols() - 1) {
const numberOfCreatedColumns = datamap.createCol(void 0, void 0, source);
propToColResult = datamap.propToCol(changes[i][1]);
// Populated data may contain indexes beyond current table boundaries.
propToColResult = datamap.propToCol(prop);
column = propToColResult !== null ? propToColResult : prop;

if (numberOfCreatedColumns >= 1) {
Expand Down Expand Up @@ -2716,16 +2718,20 @@ export default function Core(rootElement, userSettings, rootInstanceSymbol = fal
let physicalRow = this.toPhysicalRow(row);
let physicalColumn = this.toPhysicalColumn(column);

// We can also get cell meta for indexes beyond current table boundaries.
if (physicalRow === null) {
physicalRow = row;
}

// We can also get cell meta for indexes beyond current table boundaries.
if (physicalColumn === null) {
physicalColumn = column;
}

const colToPropResult = datamap.colToProp(column);
const prop = colToPropResult !== null ? colToPropResult : column; // We can also get meta for columns beyond the table boundaries
// TODO: Should it be possible to get cell meta for index beyond the table boundaries when data is defined as
// array of objects? Will a column index represent properly the property (integer instead of string)?
const prop = colToPropResult !== null ? colToPropResult : column;
const cellProperties = metaManager.getCellMeta(physicalRow, physicalColumn);

// TODO(perf): Add assigning this props and executing below code only once per table render cycle.
Expand Down
2 changes: 2 additions & 0 deletions src/dataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,9 @@ class DataSource {
const dataRow = this.modifyRowData(row);
let prop = column;

// Please keep in mind that we may get data by physical index or by key when we store data as array of objects.
if (Number.isInteger(column)) {
// When we store data as array of arrays a physical index is also a property.
prop = this.colToProp(column);
}

Expand Down
7 changes: 4 additions & 3 deletions src/editors/dropdownEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ class DropdownEditor extends AutocompleteEditor {
}
}

Hooks.getSingleton().add('beforeValidate', function(value, row, col) {
const propToColResult = this.propToCol(col);
const column = propToColResult !== null ? propToColResult : col;
Hooks.getSingleton().add('beforeValidate', function(value, row, prop) {
const propToColResult = this.propToCol(prop);
// Populated data may contain indexes beyond current table boundaries.
const column = propToColResult !== null ? propToColResult : prop;
const cellMeta = this.getCellMeta(row, column);

if (cellMeta.editor === DropdownEditor) {
Expand Down
2 changes: 1 addition & 1 deletion src/pluginHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ const REGISTERED_HOOKS = [
* @event Hooks#beforeValidate
* @param {*} value Value of the cell.
* @param {number} row Visual row index.
* @param {string|number} prop Property name / column index.
* @param {string|number} prop Property name / physical column index.
* @param {string} [source] String that identifies source of hook call
* ([list of all available sources]{@link https://handsontable.com/docs/tutorial-using-callbacks.html#page-source-definition}).
*/
Expand Down

0 comments on commit 156d454

Please sign in to comment.