Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
235
How to SUM a TemplateDataField column
posted

Hello,

I have a template data field column in a WebHierarchicalDataGrid and I need to sum the $ amounts.  The column will show an ASP Button if the decimal value from the database is NULL, else it will show a LinkButton whose text is the decimal amount if it is NOT NULL.

What I've been able to do so far is add a hidden column that is a BoundDataField item, and setup a SUM calculation for it.  The tricky part is moving that sum (which is in the HTML source once the grid is rendered) over to the TemplateDataField column summary cell.

I do have some code that is achieving this:

<ClientEvents Initialize="whdgLateCharges_ContainerGrid_Initialize" />

<script type="text/javascript" id="igClientScript">
function whdgLateCharges_ContainerGrid_Initialize(sender, eventArgs) {
var summaryRow = sender.get_behaviors().get_summaryRow();
var elements = summaryRow.get_element().getElementsByClassName("igg_Summary");
elements.item(12).innerHTML = elements.item(13).innerHTML;
}
</script>

Basically this is copying the value from the 13th column in the grid (the hidden one) over to the 12th.  However, I need this to work in IE7/IE8, and the javascript function .getElementsByClassName is not supported.  So I tried replacing it with $(.igg_Summary') but that breaks my code completely.

Any ideas how I can use JQuery and cut out this javascript function all together? 

  • 29417
    Verified Answer
    Offline posted

    Hello Brian , 

    Thank you for posting in our forum. 

    Generally you can use jquery however make sure that you have it loaded on the page.

    For example the code for setting the text from one summary cell to another could look like this:

     

    <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.js"></script>

        <script type="text/javascript">

            function whdg_init(sender, e) {

                var summaryRow = sender.get_behaviors().get_summaryRow();

                var elements = $(summaryRow.get_element()).find(".igg_Summary");

                  $(elements[3]).text($(elements[2]).text());

            }   

        </script> 

    You could use just jQuery however it would be best to use it inside the Initialize event of the grid since if you use it before the Initialize event has executed , the grid won’t have fully initialized yet and the summary row may not be available yet. 

    I’ve attached a sample for your reference. Let me know if you have any questions or concerns.

     

    Best Regards,

    Maya Kirova

    Developer Support Engineer II

    Infragistics, Inc.

    http://es.infragistics.com/support

     

    wdg_sum_tempColumn.zip