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

Server-side column selected event

2 Answers 116 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Al
Top achievements
Rank 1
Iron
Iron
Iron
Al asked on 15 Jul 2015, 12:07 PM

Hi,

I have a grid where the user will click a column and I want to handle that column-click server-side. I tried handling OnSelectedCellChanged (with EnablePostBackOnRowClick="true") but that only works when clicking cells, not columns headers. How can I achieve this?

2 Answers, 1 is accepted

Sort by
0
Al
Top achievements
Rank 1
Iron
Iron
Iron
answered on 17 Jul 2015, 07:13 AM

 I have found a half-solution for this:

<ClientSettings
    ClientEvents-OnColumnClick="grdRaw_OnColumnClick"
    Selecting-CellSelectionMode="Column"
    EnablePostBackOnRowClick="true"
    >
</ClientSettings>
 

The only thing is that now when clicking a cell the whole column is no longer selected ie. CellSelectionMode="Column"  seems to have no effect.

What I want is that a whole column is selected when the user clicks the column header or any cell in that column and then do a postback - any ideas?

0
Konstantin Dikov
Telerik team
answered on 20 Jul 2015, 07:26 AM
Hello Al,

If the selection stopped working after you have included those client settings, it is possible that there is a JavaScript error present on the page that breaks the functionality of the controls.

Notwithstanding, for handling the header column click on server-side you can use the client-side OnColumnClick event and fire custom command through the grid's MasterTableView with the column's UniqueName:
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
    <script type="text/javascript">
        function grdRaw_OnColumnClick(sender, args) {
            sender.get_masterTableView().fireCommand("ColumnHeaderClick", args.get_gridColumn().get_uniqueName());
        }
    </script>
</telerik:RadCodeBlock>
 
<asp:Label runat="server" ID="Label1"></asp:Label>
 
<telerik:RadGrid runat="server" ID="RadGrid1" OnNeedDataSource="RadGrid1_NeedDataSource" OnItemCommand="RadGrid1_ItemCommand">
    <ClientSettings  ClientEvents-OnColumnClick="grdRaw_OnColumnClick"
        Selecting-CellSelectionMode="Column"
        EnablePostBackOnRowClick="true">
    </ClientSettings>
</telerik:RadGrid>

And the code-behind:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == "ColumnHeaderClick")
    {
        var clickedColumnName = e.CommandArgument.ToString();
        Label1.Text = clickedColumnName;
    }
}

As for the Column CellSelectionMode, this property will select the cells for the entire column only when you click on the column's header. Detailed information on this matter is available in the following help article:

Hope this helps.


Regards,
Konstantin Dikov
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
Tags
Grid
Asked by
Al
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Al
Top achievements
Rank 1
Iron
Iron
Iron
Konstantin Dikov
Telerik team
Share this question
or