Our blazing fast Grid component built with pure JavaScript


Post by manuelbr3 »

Hi!, we've encountered with a problem when we use the grid's summary feature, along with the selectedOnly option set to true.

When there are no lines selected, all the lines are taken into account for summarizing, when should be the opposite.

This is because of the fact that the sum function provided to the aggregate column definition (custom sumDocumentLinesValues function, getting {sum, record} parameters) is always called. And since there is no way of knowing if the provided record is selected or not, we cannot modify it in order to know when to sum and when not.

export function sumDocumentLinesValues(column) {
	return function (sum, record) {
		sum += !record.isParent ? record[column] : 0;
		return sum;
	};
}

I really appreciate your help in this topic. Thank you so much in advance!


Post by marcio »

Hey manuelbr3,

That's the expected behavior on our side, what's your expectation regarding the behavior of the Grid on this?

Best regards,
Márcio


Post by manuelbr3 »

Hi Marcio,

When there are no lines selected, should be expected that the summary is 0, isn't it?,

Best regards,

Manuel


Post by alex.l »

Hi Manuel, that's by design. If nothing selected, it's 0 yes, but 0 is not informative unlike total summary information.
There is a grid.selectedRecords array that you can check in your summary method to know if any records selected or not.
https://bryntum.com/products/grid/docs/api/Grid/view/mixin/GridSelection#property-selectedRecords

All the best,
Alex


Post by manuelbr3 »

Hi Alex,

There is no way I can access the grid instance inside the summary function, since it belongs to the class context and it is not accessible from the inside of the mentioned function.

sumDocumentLinesValues(column) {
		return function (sum, record) {
			const selectedRecords = this.treeGrid.selectedRecords; //Error, there is no treeGrid
			sum += !record.isParent ? record[column] : 0;
			return sum;
		};
	}

There may be something I'm missing?


Post by marcio »

Hey manuelbr3,

If you do like the following you could access the external context

sumDocumentLinesValues(column) {
	const me = this;
	return function (sum, record) {
			const selectedRecords = me.treeGrid.selectedRecords;
			sum += !record.isParent ? record[column] : 0;
			return sum;
		};
	}

Best regards,
Márcio


Post Reply