Our blazing fast Grid component built with pure JavaScript


Post by bensullivan »

Hi

I'm getting a NaN render for some summaries I have configured for a dynamically added child column:
Screen Shot 2019-11-07 at 20.40.51.png
Screen Shot 2019-11-07 at 20.40.51.png (84.35 KiB) Viewed 2038 times
I'm configuring the column like this:
{
                    field: newMonthForecastFieldName,
                    text: 'Forecast<br>$',
                    type: 'number',
                    draggable: false,
                    width: 150,
                    align: 'center',
                    region: 'middle',
                    summaries: [
                        {
                            sum(result, record) {
                                return result + record.newMonthForecastFieldName;
                            },
                            renderer: ({sum}) => `Forecast 1: ${sum}`
                        },
                        {
                            sum(result, record) {
                                return result + record.newMonthForecastFieldName;
                            },
                            renderer: ({sum}) => `Forecast 2: ${sum}`
                        }
                    ]
                }
Is this supported?

Also, is it possible to apply styling to a summary renderer in the same way you can to a cellElement in a column renderer?

I have attached the ng8 project that reproduces what I'm trying to do.

Thanks

Ben
Attachments
ng8.zip
(4.45 MiB) Downloaded 160 times

Post by pmiklashevich »

Hello,

I haven't checked your attachment but I'm sure you have NaN because you do:
undefined + 1
//NaN
Please set a breakpoint to your "sum" function and make sure record.newMonthForecastFieldName is defined. Maybe there is a typo in the field name or the value is not defined indeed. Make sure type/defaultValue is correct in your Model definition. Please see "Defining fields" chapter of the docs here: https://www.bryntum.com/docs/scheduler/#Common/data/Model

Please keep on mind that according to the docs you can provide "seed" - Initial value when using a function as sum

Also I'd like to highlight that testcase is a simple example which has minimal code to reproduce the issue. Debugging user applications cannot be done in scope of the forum support. In your case I would modify https://bryntum.com/examples/grid/summary/ demo. For example if you replace city column with the following code:
{
    text      : 'City',
    field     : 'city',
    width     : 200,
    locked    : true,
    summaries : [
        {
            sum      : (result, record) => {
                return result + record.test; // point to a field that does not exist
            },
            renderer : ({ sum }) => `1. Most entries: ${sum}`
        },
        {
            seed : 'default',
            sum      : (result, record) => {
                return result + record.city; // strings are concatenated
            },
            renderer : ({ sum }) => `2. Most entries: ${sum}`
        }
    ]
},
Снимок экрана 2019-11-07 в 17.45.49.png
Снимок экрана 2019-11-07 в 17.45.49.png (21.39 KiB) Viewed 2035 times
That would be a testcase.

Cheers,
Pavel

Pavlo Miklashevych
Sr. Frontend Developer


Post by pmiklashevich »

Also, is it possible to apply styling to a summary renderer in the same way you can to a cellElement in a column renderer?
No, it's not supported. But you can style it using CSS, for example:
.b-grid-footer[data-column="city"] {
	background: greenyellow;
}
Снимок экрана 2019-11-07 в 17.57.07.png
Снимок экрана 2019-11-07 в 17.57.07.png (25.06 KiB) Viewed 2035 times

Pavlo Miklashevych
Sr. Frontend Developer


Post Reply