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

Total a COLUMN on column click

1 Answer 58 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
KIRAN RAJ
Top achievements
Rank 1
KIRAN RAJ asked on 15 Dec 2011, 05:18 PM
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..?

1 Answer, 1 is accepted

Sort by
0
Casey
Top achievements
Rank 1
answered on 15 Dec 2011, 06:50 PM
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
Tags
Ajax
Asked by
KIRAN RAJ
Top achievements
Rank 1
Answers by
Casey
Top achievements
Rank 1
Share this question
or