|
. . .
<SfGrid TValue="Order" ID="Grid" AllowSorting="true" ColumnMenuItems=@MenuItems ShowColumnMenu="true" ShowColumnChooser="true" AllowFiltering="true" AllowPaging="true">
<GridFilterSettings Type="Syncfusion.Blazor.Grids.FilterType.Excel"></GridFilterSettings>
<SfDataManager Adaptor="Adaptors.CustomAdaptor">
<CustomAdaptorComponent></CustomAdaptorComponent>
</SfDataManager>
<GridPageSettings PageSize="8"></GridPageSettings>
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="@TextAlign.Center" Width="140"></GridColumn>
<GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" TextAlign="@TextAlign.Center" Width="140"></GridColumn>
</GridColumns>
</SfGrid>
@code{
public string[] MenuItems = new string[] { "ColumnChooser", "Filter" };
. . .
} |
|
<SfGrid @ref="_grid" DataSource="@Employees" Height="315" AllowReordering="true">
<GridEvents TValue="EmployeeData" OnLoad="LoadGridOrder"></GridEvents>
<GridColumns>
<GridColumn Field=@nameof(EmployeeData.EmployeeID) HeaderText="EmployeeID" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<GridColumn Field="Name.FirstName" HeaderText="First Name" Width="150"></GridColumn>
<GridColumn Field="Name.LastName" HeaderText="Last Name" Width="130"></GridColumn>
<GridColumn Field=@nameof(EmployeeData.Title) HeaderText="Title" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn>
</GridColumns>
</SfGrid>
private async Task LoadGridOrder()
{
Use any of the below methods
//await _grid.ReorderColumns("EmployeeID", "Title"); - using ReorderColumns(Defines the origin field name, Defines the destination field name.)
await _grid.ReorderColumnByIndex(0, 2); - using ReorderColumnByIndex ReorderColumnByIndex(Defines the origin field index, Defines the destination field index )
} |
|
<SfGrid @ref="_grid" DataSource="@Employees" Columns="@Cols" Height="315" AllowReordering="true">
</SfGrid>
@code{
private SfGrid<EmployeeData> _grid { get; set; }
public List<GridColumn> Cols = new List<GridColumn>();
public List<EmployeeData> Employees { get; set; }
protected override void OnInitialized()
{
#pragma warning disable BL0005
Cols = new List<GridColumn>() {
new GridColumn() { Field = "Title" },
new GridColumn() { Field = "Name.LastName" },
new GridColumn() { Field = "Name.FirstName" },
new GridColumn() { Field = "EmployeeID" }
}; - here you can define the Columns order as based on your wish.
#pragma warning restore BL0005
Employees = Enumerable.Range(1, 9).Select(x => new EmployeeData()
{
EmployeeID = x,
Name = new EmployeeName()
{
FirstName = (new string[] { "Nancy", "Andrew", "Janet", "Margaret", "Steven" })[new Random().Next(5)],
LastName = (new string[] { "Davolio", "Fuller", "Leverling", "Peacock", "Buchanan" })[new Random().Next(5)]
},
Title = (new string[] { "Sales Representative", "Vice President, Sales", "Sales Manager",
"Inside Sales Coordinator" })[new Random().Next(4)],
}).ToList();
}
. . .
} |
|
<SfGrid @ref="_grid" DataSource="@Employees" Columns="@Cols" Height="315" AllowReordering="true">
</SfGrid>
@code{
private SfGrid<EmployeeData> _grid { get; set; }
public List<GridColumn> Cols = new List<GridColumn>();
SfButton button;
public List<EmployeeData> Employees { get; set; }
//define the template column here
RenderFragment<object> g = (value) =>
{
EmployeeData order = value as EmployeeData;
return b =>
{
b.AddContent(0,@<Syncfusion.Blazor.Buttons.SfButton Content="@order.Title" />);
};
};
protected override void OnInitialized()
{
#pragma warning disable BL0005
Cols = new List<GridColumn>() {
new GridColumn() { Field = "Title" },
new GridColumn() { Field = "Name.LastName" },
new GridColumn() { Field = "Name.FirstName" },
new GridColumn() { Field = "EmployeeID" },
new GridColumn() { HeaderText = "Template Column", Template= g }
};
#pragma warning restore BL0005
. . .
} |