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

GridDragDropColumn with AutoGenerated columns

1 Answer 139 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bruno
Top achievements
Rank 1
Bruno asked on 21 Dec 2012, 01:16 PM

Hello,

I am new at Telerik RadGrid in Ajax/ASP .NET.

I am trying to allow the user of my application to be able to re order the columns of my RadGrid. I found on your website that :

GridDragDropColumn  has to be inserted in the Columns collection of a GridTableView, But as my RadGrid columns are autogenerated, I have no <Column> tag in the description of my RadGrid. So I am trying to understand where should the GridDragDropColumn  tag be inserted to allow Columns drag and drop (and re-ordering).
I tried to insert it in the <Columns> description of my MasterTableView (see the code below) but when running it, I cannot drag any of my columns ?

Another point is that I want that my columns can also be sorted by one click on the header of the column. Is that compatible with the GridDragDropColumn  option ?

Thank your for your help.

Here is the code of my grid in my ASPX file :

<telerik:RadGrid ID="GridView1" runat="server"
        ActiveItemStyle-BorderStyle="Solid" AllowSorting="True"
        AllowMultiRowSelection="True" AllowFilteringByColumn="True"  
        TableLayout="Fixed" ValidationSettings-EnableValidation="False"
        ScrollHeight="200px"  Height="700px"  Width = "98%" table-layout="auto">
    <MasterTableView  TableLayout="auto">
   <Columns>
    <telerik:GridDragDropColumn HeaderStyle-Width="18px" />
                        
      </Columns>
 
       <NestedViewTemplate>
           <asp:Panel runat="server" ID="configControlContainer" CssClass="viewWrap" Visible="true" BackColor="PaleGoldenrod">
            <table>
           <tr>
           <td><telerik:RadTextBox ID="RadTextbox1" runat="server">
           </telerik:RadTextBox>
            </td>
             </tr>
             <tr>
           <td><telerik:RadButton ID="RadButton1" Text="Confirm" runat="server"
                                                      OnClick="btn_Click">
            </telerik:RadButton>
 
            
             </td>
              </tr>
              </table>
            </asp:Panel>
            </NestedViewTemplate>
 
              <DetailTables>
                        
             </DetailTables>
          </MasterTableView>
           <ClientSettings  AllowRowsDragDrop="true">
              <Selecting AllowRowSelect="True" EnableDragToSelectRows="false" />
              <Scrolling AllowScroll="True" ScrollHeight="475px" UseStaticHeaders="true" FrozenColumnsCount="1" SaveScrollPosition="True" />
            </ClientSettings>
              
          </telerik:RadGrid>

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 25 Dec 2012, 02:43 PM
Hello Bruno,

I have created a sample RadGrid web site where I implemented the requested functionality. On my side the DragDropColumn and colum reordering work as expected. Please check out the attached application and execute your custom logic in the drag-n-drop events as demonstrated in the following demo:
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/draganddrop/defaultcs.aspx

Additionally, you can change the order of the DragDropColumn::
Copy Code
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        GridColumn column = RadGrid1.MasterTableView.GetColumnSafe("DragDropColumn") as GridColumn;
        column.OrderIndex = RadGrid1.MasterTableView.RenderColumns.Length;
        RadGrid1.MasterTableView.Rebind();
    }
}

To understand the difference between reordering and swapping columns on client, please check out the following topic:
http://www.telerik.com/help/aspnet-ajax/grid-reordering-columns.html

I hope this will prove helpful.

Regards,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Bruno
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or