New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

Reordering

You can allow users to set the order of the treelist columns by dragging and dropping them. Just set the ClientSettings.Reordering.AllowColumnsReorder property to True. When the user drags a column header to a new location, the treelist indicates where the column will be inserted when it is dropped:

Additionally, in case you enabled scrolling and have a horizontal scroll for navigation, the treelist would be "smart" to auto-scroll when you drag columns and reach the end of the visible region (when you attempt to reorder the column with another outside of the visible area).

There are two possible modes for column reordering: client and server-side. If you want to reorder columns on client,set the ClientSettings.Reordering.ReorderColumnsOnClient property to True.

  • When columns are reordered on the client, The ClientSettings.Reordering.ColumnsReorderMethod property determines what happens when the user drops a column in a new position. When ColumnsReorderMethod is "Swap" (the default), switches places of two columns. Columns between them do not change order.When ColumnsReorderMethod is "Reorder", places the first (dragged) column at the place of the second(dropped on) column. Columns between them also change order.

  • When columns are reordered on the server, the treelist uses the "swap" method multiple times to re-order columns.

Reordering columns programmatically

When columns are created programmatically, they appear in the same order that they were added to theColumns collection. You can reorder columns dynamically in server-side code using any of the following methods:

  • The SwapColumns(String,String) method accepts the UniqueNames for two columns to swap:
treelist.SwapColumns("FirstName", "LastName");
treelist.SwapColumns("FirstName", "LastName")
  • The SwapColumns(Int32,Int32) method accepts the indexes of two columns to swap:
treelist.SwapColumns(3, 4);
treelist.SwapColumns(3, 4)
  • The OrderIndex property lets you change the position of columns to move them to a specific location:
TreeListColumnsCollection cols = treelist.Columns;
TreeListColumn c = cols.FindByUniqueName(columnName);
if (c != null)
{
    int start = c.OrderIndex;
    for (int i = start; i < cols.Count; i++)
    {
        c = cols[i];
        if (i < cols.Count - 1)
            c.OrderIndex = i + 1;
        else
            c.OrderIndex = start;
    }
}
Dim cols As TreeListColumnsCollection = treelist.Columns
Dim c As TreeListColumn = cols.FindByUniqueName(columnName)
If c IsNot Nothing Then
    Dim start As Integer = c.OrderIndex
    For i As Integer = start To cols.Count - 1
        c = cols(i)
        If i < cols.Count - 1 Then
            c.OrderIndex = i + 1
        Else
            c.OrderIndex = start
        End If
    Next
End If

When using the OrderIndex property to reorder columns, make sure that you assign values so that no two columns have the same index and no index is omitted.

In this article