This is a migrated thread and some comments may be shown as answers.

Aggregate numeric values for nvarchar column

2 Answers 138 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Clive Hoggar
Top achievements
Rank 1
Clive Hoggar asked on 30 May 2016, 02:15 PM

Hi

Please help me out!

I have recently purchased a licence for the Q2 2016 devcraft tools and I am working on a website update...

I have a database in which numeric values have been recorded historically in an nvarchar column. I can't readily change the column type as it is in production and has several years of data in it.

However I would now like to use the aggregate function to put sum totals in a footer.  How can I achieve this from where we are now - i.e. with a non-numeric data column? Obviously I get an error just adding aggregate="Sum" ( 'Sum is not supported for type system.object').

I tried cheating by just changing the column from gridbound to gridnumeric but it is not so easily fooled!

Can you suggest what is the best way to get from the nvarchar database column I have now,  to getting an aggregate sum in the footer?

Thanks

Clive

Using Q2 2016 controls in VS 2015

 

2 Answers, 1 is accepted

Sort by
0
Clive Hoggar
Top achievements
Rank 1
answered on 31 May 2016, 10:42 AM

Just to add....

I have tried creating a new numeric column and then processing the nvarchar item in itemdatabound event to populate the new column with decimal values. That works up to the point I tried to add Aggregate=sum to the numeric field I created.

Runtime Error then is "[column]  is neither a DataColumn nor a DataRelation for table"

Still stumped...

Clive

 

0
Viktor Tachev
Telerik team
answered on 31 May 2016, 12:02 PM
Hello Clive,

The GridNumericColumn expects that the underlying data will be a numeric value. This is why it is expected to see an error when the field in the database keeps the data as string.

You said that updating the field in the database to numeric is not an option. In that case you would need to implement the logic for the aggregates manually. You can set the AggregateFunction for the column to Custom. With that setup the CustomAggregate event will be raised by the grid. In the handler you can add the custom logic that will be used to calculate the aggregate.



Regards,
Viktor Tachev
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Grid
Asked by
Clive Hoggar
Top achievements
Rank 1
Answers by
Clive Hoggar
Top achievements
Rank 1
Viktor Tachev
Telerik team
Share this question
or