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

Create a Dynamic Contingency table

1 Answer 51 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Simone
Top achievements
Rank 1
Simone asked on 03 Jul 2015, 07:28 AM

Good morning,

I'm trying to create a contingency table ( you can see a simple example in the image) but I don't find an optimal solution. What I tried to do was to use a RadGrid. The "problem" is that I want to populate the table in code behind (I use c sharp). In particular I have 2 arrays: in this example one for sex (male or female) and one for handedness (right- or left-handed). All the other data (the numbers) must be initially empty. The second "problem" is that I'd like to calculate the sum in client side in order to avoid a postback each time I insert a variable. What I tried to do was to create a dataTable and insert it as datasource. For the column with the sum I used a calculatedGridColumn but I had problem if the value is empty because I was not able to convert it as 0 (I don't want to show the empty value as 0 initially). In order to calculate the total each time I insert a new value I wasn't able to sum the value of each row but I subtract the value when click the cell and then re add the new value inserted (it's a bad method). There's no way to re evaluate the total each time I insert a new value?. As I said remember that the table is created dynamically.

If someone has a good solution for this problem please help me.

Thanks

1 Answer, 1 is accepted

Sort by
0
Angel Petrov
Telerik team
answered on 08 Jul 2015, 05:36 AM
Hello,

For you scenario it seems that you may use a pivot grid which will automatically calculate the totals for you. Is there any reason which prevents you from using this control?

As for the insert issue it would be hard to provide a precise solution for it without having a better understanding of the exact implementation. That said can you share with us the markup and code-behind of the page?

One other thing since you mentioned that the data is held on the server but the calculations are done on the client you may try modifying the code so that the grid is bound programmatically as demonstrated here. The idea is to use a web method/web service which to return the entire data on the client. This will allow you to populate the grid and do some calculations according to your preferences.

Regards,
Angel Petrov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Simone
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Share this question
or