Skip to content

Commit

Permalink
Reverted part of changes - methods getSourceDataAtCol and `getSourc…
Browse files Browse the repository at this point in the history
…eDataAtCell` will not be fixed, `colToProp` will need yet some work #7031
  • Loading branch information
wszymanski committed Jul 23, 2020
1 parent 6e69fba commit b9fbc01
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
8 changes: 5 additions & 3 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,7 @@ export default function Core(rootElement, userSettings, rootInstanceSymbol = fal
changes.push([
input[i][0],
prop,
dataSource.getAtCell(this.toPhysicalRow(input[i][0]), prop),
dataSource.getAtCell(this.toPhysicalRow(input[i][0]), input[i][1]),
input[i][2],
]);
}
Expand Down Expand Up @@ -2426,9 +2426,10 @@ export default function Core(rootElement, userSettings, rootInstanceSymbol = fal
*
* @memberof Core#
* @function getSourceDataAtCol
* @param {string|number} column Column property which may be also a physical column index.
* @param {number} column Visual column index.
* @returns {Array} Array of the column's cell values.
*/
// TODO: Getting data from `sourceData` should work always on physical indexes.
this.getSourceDataAtCol = function(column) {
return dataSource.getAtColumn(column);
};
Expand Down Expand Up @@ -2501,9 +2502,10 @@ export default function Core(rootElement, userSettings, rootInstanceSymbol = fal
* @memberof Core#
* @function getSourceDataAtCell
* @param {number} row Physical row index.
* @param {string|number} column Column property which may be also a physical column index.
* @param {number} column Visual column index.
* @returns {*} Cell data.
*/
// TODO: Getting data from `sourceData` should work always on physical indexes.
this.getSourceDataAtCell = function(row, column) {
return dataSource.getAtCell(row, column);
};
Expand Down
9 changes: 7 additions & 2 deletions src/dataMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,15 @@ class DataMap {
/**
* Returns property name that corresponds with the given column index.
*
* @param {string|number} column Visual column index.
* @returns {string|number|null} Column property which may be also a physical column index.
* @param {string|number} column Visual column index or another passed argument.
* @returns {string|number} Column property, physical column index or passed argument.
*/
colToProp(column) {
// TODO: This should be removed. Please keep in mind that the `getSourceDataAtCol` and `getSourceDataAtCell` use it.
if (Number.isInteger(column) === false) {
return column;
}

const physicalColumn = this.instance.toPhysicalColumn(column);

// Cached property.
Expand Down
12 changes: 2 additions & 10 deletions src/dataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,21 +247,13 @@ class DataSource {
* Returns a single value from the data.
*
* @param {number} row Physical row index.
* @param {number} column Column property which may be also a physical column index.
* @param {number} column Visual column index.
* @returns {*}
*/
getAtCell(row, column) {
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.
// TODO: What about physical index which do not have visual representation?
if (Number.isInteger(column) && this.dataType !== 'array') {
// When we store data as array of arrays a physical index is also a property.
prop = this.colToProp(this.hot.toVisualColumn(column));
}

return this.getAtPhysicalCell(row, prop, dataRow);
return this.getAtPhysicalCell(row, this.colToProp(column), dataRow);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/editorManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,9 @@ class EditorManager {

if (editorClass && td) {
const prop = this.instance.colToProp(visualColumnToCheck);

const originalValue =
this.instance.getSourceDataAtCell(this.instance.toPhysicalRow(visualRowToCheck), prop);
this.instance.getSourceDataAtCell(this.instance.toPhysicalRow(visualRowToCheck), visualColumnToCheck);

this.activeEditor = getEditorInstance(editorClass, this.instance);
// Using not modified coordinates, as we need to get the table element using selection coordinates.
Expand Down
2 changes: 1 addition & 1 deletion src/editors/selectEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class SelectEditor extends BaseEditor {
*/
refreshValue() {
const physicalRow = this.hot.toPhysicalRow(this.row);
const sourceData = this.hot.getSourceDataAtCell(physicalRow, this.prop);
const sourceData = this.hot.getSourceDataAtCell(physicalRow, this.col);
this.originalValue = sourceData;

this.setValue(sourceData);
Expand Down
2 changes: 1 addition & 1 deletion src/editors/textEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ class TextEditor extends BaseEditor {
*/
refreshValue() {
const physicalRow = this.hot.toPhysicalRow(this.row);
const sourceData = this.hot.getSourceDataAtCell(physicalRow, this.prop);
const sourceData = this.hot.getSourceDataAtCell(physicalRow, this.col);
this.originalValue = sourceData;

this.setValue(sourceData);
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/filters/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ class Filters extends BasePlugin {
const visualIndex = this.hot.toVisualColumn(column);
const data = [];

arrayEach(this.hot.getSourceDataAtCol(column), (value, rowIndex) => {
arrayEach(this.hot.getSourceDataAtCol(visualIndex), (value, rowIndex) => {
const { row, col, visualCol, visualRow, type, instance, dateFormat } = this.hot
.getCellMeta(rowIndex, visualIndex);

Expand Down

0 comments on commit b9fbc01

Please sign in to comment.