Dan-Petter
Top achievements
Rank 1
Dan-Petter
asked on 27 May 2014, 06:22 AM
Hi
i'm working on a script where i need to add/remove aggregation dynamically (i have own gui to control aggregation on appropriate fields)
add aggregation was ok by using
dataSource.group(groups);
dataSource.aggregate(aggregates);
grid.columns[parseInt(column)].groupFooterTemplate = aggr + " #=" + aggr.toLowerCase() + "#";
grid.setDataSource(dataSource);
this will remove aggregation and grouping:
dataSource.group([]);
dataSource.aggregate([]);
grid.columns[parseInt(column)].groupFooterTemplate = "";
grid.setDataSource(dataSource);
but if i try to group again after removing i get the following error:
Uncaught TypeError: undefined has no properties, but by not setting the template to an empty string i get a $aggr is not defined.
Have can i remove aggregation, reset the footer template so i don't get the undefined errors and still have grouping?
i'm working on a script where i need to add/remove aggregation dynamically (i have own gui to control aggregation on appropriate fields)
add aggregation was ok by using
dataSource.group(groups);
dataSource.aggregate(aggregates);
grid.columns[parseInt(column)].groupFooterTemplate = aggr + " #=" + aggr.toLowerCase() + "#";
grid.setDataSource(dataSource);
this will remove aggregation and grouping:
dataSource.group([]);
dataSource.aggregate([]);
grid.columns[parseInt(column)].groupFooterTemplate = "";
grid.setDataSource(dataSource);
but if i try to group again after removing i get the following error:
Uncaught TypeError: undefined has no properties, but by not setting the template to an empty string i get a $aggr is not defined.
Have can i remove aggregation, reset the footer template so i don't get the undefined errors and still have grouping?
6 Answers, 1 is accepted
0
Hello,
Is "dataSource" the dataSource of the grid? If yes, then setting the group and aggregates will cause the grid to refresh itself with the old template which will cause the error. In this case I would suggest to use the setOptions method to update the column templates instead of setDataSource. Here is a small example that demonstrates how to use it. As an alternative approach, I can suggest to use a condition in the template to check if there are any aggregates instead of recreating the templates.
You might also consider using the query method instead of both group and aggregate in order to avoid triggering the change event twice.
Regards,
Daniel
Telerik
Is "dataSource" the dataSource of the grid? If yes, then setting the group and aggregates will cause the grid to refresh itself with the old template which will cause the error. In this case I would suggest to use the setOptions method to update the column templates instead of setDataSource. Here is a small example that demonstrates how to use it. As an alternative approach, I can suggest to use a condition in the template to check if there are any aggregates instead of recreating the templates.
You might also consider using the query method instead of both group and aggregate in order to avoid triggering the change event twice.
Regards,
Daniel
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
0
Dan-Petter
Top achievements
Rank 1
answered on 30 May 2014, 06:17 AM
Hey
Thanks, using the code from your clearAggregation method in the example removes all aggregation and grouping without errors. If i group a column after removing aggregation the error is back: Uncaught TypeError: undefined has no properties in VMxxxx
(function(data
/**/) {
var o,e=kendo.htmlEncode;with(data.TestFieldName){o='Sum '+(sum)+'';}return o;
})
The same happen if i don't remove the group and instead using: dataSource.group([{ field: "TestFieldName" }]);
Thanks, using the code from your clearAggregation method in the example removes all aggregation and grouping without errors. If i group a column after removing aggregation the error is back: Uncaught TypeError: undefined has no properties in VMxxxx
(function(data
/**/) {
var o,e=kendo.htmlEncode;with(data.TestFieldName){o='Sum '+(sum)+'';}return o;
})
The same happen if i don't remove the group and instead using: dataSource.group([{ field: "TestFieldName" }]);
0
Hello again,
Can the problem be reproduced in the example from my previous reply? If yes, then could you provide the exact steps? If it cannot be reproduced then could you modify it so that it replicates the error?
Regards,
Daniel
Telerik
Can the problem be reproduced in the example from my previous reply? If yes, then could you provide the exact steps? If it cannot be reproduced then could you modify it so that it replicates the error?
Regards,
Daniel
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
0
Dan-Petter
Top achievements
Rank 1
answered on 02 Jun 2014, 05:24 AM
Hi
Yes i can, please check: http://jsbin.com/muwenovo/1/edit
the only change in this code is the one line in the remove function from
dataSource.group();
to
dataSource.group([{field: "UnitsInStock"}]);
Yes i can, please check: http://jsbin.com/muwenovo/1/edit
the only change in this code is the one line in the remove function from
dataSource.group();
to
dataSource.group([{field: "UnitsInStock"}]);
0
Hi,
Thanks for updating the example. It seems that the group footer will not be recreated unless there is a non empty groupFooterTemplate. Adding a space when clearing the template should resolve the problem. I updated the jsBin.
Regards,
Daniel
Telerik
Thanks for updating the example. It seems that the group footer will not be recreated unless there is a non empty groupFooterTemplate. Adding a space when clearing the template should resolve the problem. I updated the jsBin.
Regards,
Daniel
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
0
Dan-Petter
Top achievements
Rank 1
answered on 03 Jun 2014, 12:42 PM
Hi
Lot of time spent on a single space =)
Thanks for the help, everything is working great now.
Regards
Dan
Lot of time spent on a single space =)
Thanks for the help, everything is working great now.
Regards
Dan