Page 1 of 1

Summary selectedOnly sum all when there are no lines selected

Posted: Wed Mar 15, 2023 5:52 pm
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!


Re: Summary selectedOnly sum all when there are no lines selected

Posted: Wed Mar 15, 2023 9:34 pm
by marcio

Hey manuelbr3,

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


Re: Summary selectedOnly sum all when there are no lines selected

Posted: Thu Mar 16, 2023 11:53 am
by manuelbr3

Hi Marcio,

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

Best regards,

Manuel


Re: Summary selectedOnly sum all when there are no lines selected

Posted: Thu Mar 16, 2023 2:14 pm
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


Re: Summary selectedOnly sum all when there are no lines selected

Posted: Thu Mar 16, 2023 6:17 pm
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?


Re: Summary selectedOnly sum all when there are no lines selected

Posted: Thu Mar 16, 2023 7:37 pm
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;
		};
	}