Different data returned

Tags: #<Tag:0x00007efc6b7831b0>
flights.Hot.hot.getDataAtCol(3)
(20) ["BA2696", "AT803", "BA2762", "BA2578", "BA2708", "BA2273", "BA2652", "TK1998", "D82856", "EZS8478", "DY7015", "EZY8725", "EZY8611", "SU2589", "BA2944", "EZY895", "EZY8719", "UX1016", "EZY8553", "EZY8879"]
flights.Hot.hot.getSourceDataAtCol(3)
(20) ["BA2696", "AT803", "BA2762", "BA2578", "BA2708", "BA2273", "BA2652", "TK1998", "D82856", "EZS8478", "DY7015", "EZY8725", "EZY8611", "SU2589", "BA2944", "EZY895", "EZY8719", "UX1016", "EZY8553", "EZY8879"]

As you can see… both methods return the same thing, but, after ordering one of the columns in the table I get the following:

flights.Hot.hot.getDataAtCol(3)
(20) ["BA2696", "AT803", "BA2762", "BA2578", "BA2708", "BA2652", "D82856", "DY7015", "BA2944", "UX1016", "BA2273", "TK1998", "EZS8478", "EZY8725", "EZY8611", "SU2589", "EZY895", "EZY8719", "EZY8553", "EZY8879"]
flights.Hot.hot.getSourceDataAtCol(3)
(20) ["BA2696", "AT803", "BA2762", "BA2578", "BA2708", "BA2273", "BA2652", "TK1998", "D82856", "EZS8478", "DY7015", "EZY8725", "EZY8611", "SU2589", "BA2944", "EZY895", "EZY8719", "UX1016", "EZY8553", "EZY8879"]

SourceData order is not being synced with what’s visible on the table.

This affects me because I have the following piece of code which is fired at afterChange event

changes.forEach(([row, field, oldVal, newVal]) => {
      if (this.nothingChanged(oldVal, newVal)) {
        return;
      }

      changed = true;

      const id = this.hot.getSourceDataAtRow(row).id;

And because row is what’s visible on the table (and id is not shown in the table, therefore not gettable with getDataAtRow) I’m getting incorrect data.

Is this intended behaviour or a bug?

Hi @arthur.kirkosa

getData methods are made to return current state after reordering, sorting, filtering (visual indexes) and getSourceData methods will return the state before this actions (physical indexes).

If you could share a demo with a step by step scenario and let me know what you would like to get instead I’ll check what can be done.

The thing I’m interested in is to have indices in getSourceData be similar with getData because there are times when you’d like to get additional info from your source data that is not present in the table (like the id in my case) and the row that’s being changed in a reordered table might not match the row in the SourceData

Or is there a way to sort the SourceData manually? (I had to have a separate copy of the source data, the one I was passing to HOT and have that mapped into a new array in accordance to how a readonly column from getData was sorted.

The sourceData remains the same no matter what you do. We use it to manipulate with visual incides.
That http://jsfiddle.net/handsoncode/wzLb86a8/ is the maximum that we can get from the table after a single change.

I’m doing something similar too…

Is there or will there be a method, that given a row from getData or the one that is passed when doing an action (passed to the webhook), will return the equivalent row from getSourceData?

I think that would be a good addition to the api and since you’re using something to match items from the table with the ones in the source data, it should be fairly easy.

Actually, the getSourceDataAtRow gives you the information about data under the index. You can combine it with the getLogicalRowIndex to get the data from the source.Have you tried it before?

Not sure how to use getLogicalRowIndex

Here is an example http://jsfiddle.net/zk8p1v1e/ It is held by the hiddenRows plugin but will also work when you do not hide any rows. The method returns a source (logical) index of changed cell.

I ended up doing

const visualCol = this.hot.toVisualColumn(col);
const visualRow = this.hot.toVisualRow(row);

And checked the documentation to see which methods are using visualRow and which are using physicalRow … did a lot of changes and renaming… but ended up with pretty much the same code and some row/col mappings :slight_smile: