Total a COLUMN on column click

2 posts, 0 answers
  1. KIRAN RAJ
    KIRAN RAJ avatar
    23 posts
    Member since:
    Sep 2011

    Posted 15 Dec 2011 Link to this post

    Hi guys,

    I am stucked..I m looking for code which can Total a column on a event like "column  click" .. I was able to get footer total 
    by PLACING IN ITEM DATABOUND

     protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
                 GridFooterItem footerItem = (GridFooterItem)e.Item;
         
                var total =Convert.ToInt64(objbal.ExecuteStringQuery( "select TTotal from  TAB1"));
               
               
                footerItem["Total  Capacity"].Text = "Total   Capacity: " + total.ToString() ;
    }

    i WANT TO DISPLAY COLUMN total on clicking header column  on grid.. Any sol..plzz..?
  2. Casey
    Casey avatar
    299 posts
    Member since:
    Jul 2009

    Posted 15 Dec 2011 Link to this post

    Since this is posted in the Ajax forum, I'm assuming that you want this done via ajax, or client side, right?

    There is a client event for a column click: ClientEvent-OnColumnClicked. I was able to set the footer text for the clicked column by using this event, and initiating an ajax request. 

    Here is the relevant code:
    Add this to your RadGrid:
    <ClientSettings  ClientEvents-OnColumnClick="colClick">
    </ClientSettings>

    Make sure your RadAjaxManager definition allows RadGrid1 to update RadAjaxManager1 and that RadAjaxManager1 can update RadGrid1:
    <telerik:RadAjaxManager ID="RadAjaxManager1" EnableAJAX="true" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadAjaxManager1" />
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadAjaxManager1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>


    JavaScript to initiate ajax request:
    function colClick(sender, eventArgs) {
        var col = eventArgs.get_gridColumn();
        if (col != null) {
            var ajaxMan = $find("<%= RadAjaxManager1.ClientID %>");
            if (ajaxMan != null) {
                ajaxMan.ajaxRequest(col.get_uniqueName());
            }
        }
    }

    OnAjaxRequest Code (I think you could get rid of the first line of code here and just use "fItm[e.Argument].Text" instead of "fItm[col.UniqueName].Text"):
    protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
    {
            GridColumn col = RadGrid1.MasterTableView.GetColumn(e.Argument);
            GridFooterItem fItm = RadGrid1.MasterTableView.GetItems(GridItemType.Footer)[0] as GridFooterItem;
            fItm[col.UniqueName].Text = "HERE IS THE TOTAL!!!";
    }


    I hope this helps!
    Casey
Back to Top