Sorting - Logical and physical indices (PRO)

Tags: #<Tag:0x00007efc729e3688>

Hi,

I’ve read docs about sorting and how are row indices translated from logical to physical but unfortunately I still have some problems with that. Thing is - if I sort some column (either ASC or DESC) my afterChange event fires twice, first time with correct translated row index, second time not

Could that be because I’m changing some other cells (in the same row) in the afterChange ?
Because of that I had to disable sorting completely, but it is a nice feature I would really like to have :slight_smile:

Thanks!

PS
Here is short example of what I am doing in afterChange handler:

   afterChange: (changes, source) => { 	
   if (["autofill", "alter", "edit", "paste"].indexOf(source) != -1) {
	// change - row, prop, old, new
	changes.forEach(val => {
		var hot = hotRegisterer.getInstance($scope.spreadsheet.hotInstanceID);
		var rowIndex = val[0];
		// if sorting is enabled for this hot
		if (hot.sortingEnabled) {
			// check if it is sorted and try get physical index of the changed row/cell
			rowIndex = angular.isDefined(hot.sortIndex[val[0]]) ? hot.sortIndex[val[0]][0] : val[0];
		}

		val[0] = rowIndex;
		var colName = val[1];
		var beforeChange = val[2];
		var afterChange = val[3];

		// mapping
		/*
		[{name: "Option 1", value: 1}
		 {name: "Option 2", value: 2}...
		]
		*/
		
		// someColumn is a dropdown filled with "names" from mapping
		// on save "value" from the mapping should be saved to the database, not "name"
		if (colName == "someColumn") {
			var value = 1;
			for (var i = 0; i < mapping.length; ++i) {
				var t = mapping[i];

				if (t.name == afterChange) {
					value = t.value;
					break;
				}
			}

			// additionally, when someColumn (dropdown) changes its value I
			// programmatically change 2 more cells in the same row
			if (value === 1) {
				data[rowIndex]["someOtherColumnXXX"] = "XXX";
				data[rowIndex]["someOtherColumnYYY"] = 0;

				// changed cells is array of changes which is furthermore processed before saving to the DB
				changedCells.push([rowIndex, "someOtherColumnXXX", "xxx", "XXX"]);
				changedCells.push([rowIndex, "someOtherColumnYYY", 2, 1]);

			} else if (value === 2) {
				// ....
			}

			val[3] = afterChange;
		}


		if (beforeChange !== afterChange && !(beforeChange === null && afterChange === "")) {
			changedCells.push(val);
		}
	});
}

Hi @danijel.dukaric
Could you create a demo with your complete instance’s settings?
It would be easier to investigate the issue.

Issue closed in lack of demo.