Create a Dynamic Contingency table

2 posts, 0 answers
  1. Simone
    Simone avatar
    2 posts
    Member since:
    Jun 2015

    Posted 03 Jul 2015 Link to this post

    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

  2. Angel Petrov
    Admin
    Angel Petrov avatar
    1096 posts

    Posted 08 Jul 2015 Link to this post

    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
Back to Top