|
| 1 | +--- |
| 2 | +title: Reorder |
| 3 | +page_title: Grid for Blazor | Reorder Columns |
| 4 | +description: Drag to reorder columns in the Grid for Blazor |
| 5 | +slug: components/grid/columns/reorder |
| 6 | +tags: telerik,blazor,grid,column,reorder,drag |
| 7 | +published: True |
| 8 | +position: 0 |
| 9 | +--- |
| 10 | + |
| 11 | +# Reorder Columns |
| 12 | + |
| 13 | +The Grid lets the user reorder its columns by dragging their headers. |
| 14 | + |
| 15 | +To enable the column reordering, set the `Reorderable` parameter of the grid to `true`. |
| 16 | + |
| 17 | +To prevent the user from moving a certain column, set its own parameter `Reordarable="false"`. Note that the user can still re-arrange other columns around it. |
| 18 | + |
| 19 | +>caption Enable column reordering in Telerik Grid |
| 20 | +
|
| 21 | +````CSHTML |
| 22 | +@* Drag a column header between other columns to change the columns positions. You cannot drag the command column. Note that actual CRUD operations and settings are not implemented here for brevity. *@ |
| 23 | +
|
| 24 | +<TelerikGrid Data="@GridData" |
| 25 | + Reorderable="true" |
| 26 | + Pageable="true" PageSize="10" Sortable="true" Height="300px"> |
| 27 | + <GridColumns> |
| 28 | + <GridColumn Field=@nameof(SampleData.Id) Title="Id" /> |
| 29 | + <GridColumn Field=@nameof(SampleData.Name) Title="First Name" /> |
| 30 | + <GridColumn Field=@nameof(SampleData.LastName) Title="Last Name" /> |
| 31 | + <GridCommandColumn Width="100px" Reorderable="false"> |
| 32 | + <GridCommandButton Command="Save" Icon="save" ShowInEdit="true">Update</GridCommandButton> |
| 33 | + <GridCommandButton Command="Edit" Icon="edit">Edit</GridCommandButton> |
| 34 | + <GridCommandButton Command="Delete" Icon="delete">Delete</GridCommandButton> |
| 35 | + <GridCommandButton Command="Cancel" Icon="cancel" ShowInEdit="true">Cancel</GridCommandButton> |
| 36 | + </GridCommandColumn> |
| 37 | + </GridColumns> |
| 38 | +</TelerikGrid> |
| 39 | +
|
| 40 | +@code { |
| 41 | + public List<SampleData> GridData { get; set; } |
| 42 | +
|
| 43 | + protected override void OnInitialized() |
| 44 | + { |
| 45 | + GridData = GetData(); |
| 46 | + } |
| 47 | +
|
| 48 | + private List<SampleData> GetData() |
| 49 | + { |
| 50 | + return Enumerable.Range(1, 50).Select(x => new SampleData |
| 51 | + { |
| 52 | + Id = x, |
| 53 | + Name = $"name {x}", |
| 54 | + LastName = $"Surname {x}" |
| 55 | + }).ToList(); |
| 56 | + } |
| 57 | +
|
| 58 | + public class SampleData |
| 59 | + { |
| 60 | + public int Id { get; set; } |
| 61 | + public string Name { get; set; } |
| 62 | + public string LastName { get; set; } |
| 63 | + } |
| 64 | +} |
| 65 | +```` |
| 66 | + |
| 67 | + |
| 68 | +>caption How column reordering works in the Telerik grid |
| 69 | +
|
| 70 | + |
| 71 | + |
| 72 | +## See Also |
| 73 | + |
| 74 | + * [Live Demo: Column Reordering](https://demos.telerik.com/blazor-ui/grid/column-reordering) |
0 commit comments