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

Client Update Calculated Column?

2 Answers 61 Views
Grid
This is a migrated thread and some comments may be shown as answers.
TPerry
Top achievements
Rank 1
TPerry asked on 29 Jul 2010, 01:34 PM
Hello - I have a grid that has a Quantity, a Cost, and a Total column.  Currently, the Total Column is a TemplateColumn and on ItemDataBound I manaully calculate the Total (which is Quantity * Cost) for each row.  This presents a problem when there are 100+ rows, performance wise.  I know I can change it to a Calculated Column, which would erase the need to manually calculate it in the code behind.  My problem is that the user needs to see the new Total while they are still editing the row.  With the Template column, I can use JavaScript to udpdate it, but am unable to use JS when I change it to a Calculated Column.  This seems like a pretty basic question...  Any ideas?

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 29 Jul 2010, 02:01 PM
Hello,

You can use the same logic to change the calculated text even when using GridCalculatedColumn. The following client code will give you some idea on how to set/change the cell text of calculatedcolumn.

Client Code:
<script type="text/javascript">
    function changeText() {
        var grid = $find('<%= RadGrid1.ClientID %>');
        var row = grid.get_masterTableView().get_dataItems()[0]; // getting first item
        //in your case get access to corresponding item , you can also pass the index (its based on your logic)
 
        var cell = grid.get_masterTableView().getCellByColumnUniqueName(row, "GridCalculatedColumn");  // GridCalculatedColumn is columnuniquename
        cell.innerHTML = "100"// Calculate the result and set it even the row in editmode
    }
</script>



-Shinu.
0
TPerry
Top achievements
Rank 1
answered on 29 Jul 2010, 02:32 PM
That was EXACTLY it!  Thank you, thank you, thank you!!
Tags
Grid
Asked by
TPerry
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
TPerry
Top achievements
Rank 1
Share this question
or