<GridColumn Field=@nameof(Order.CustomerID) HeaderText="Signet" Width="150" IsPrimaryKey="true" EditType="EditType.DropDownEdit">
<EditTemplate>
<SfComboBox @bind-Value="_signetValue" ID="CustomerID" Placeholder="Signets disponibles" AllowCustom="true" TItem="string" TValue="string" DataSource="@_signetsList">
</SfComboBox>
</EditTemplate>
</GridColumn>
<GridColumn Field=@nameof(Order.ShipCountry) HeaderText="Information Source" Width="200" EditType="EditType.DropDownEdit">
<EditTemplate>
<SfDropDownList ID="ShipCountry" Placeholder="Informations sources" TValue="string" TItem="Countries" DataSource="@_infoSourceList">
<DropDownListEvents TValue="string"></DropDownListEvents>
<DropDownListFieldSettings Text="Name" Value="Name"></DropDownListFieldSettings>
</SfDropDownList>
</EditTemplate>
</GridColumn>
|
<EditTemplate>
<SfComboBox Value="@_signetValue" ID="CustomerID" Placeholder="Signets disponibles" AllowCustom="true" TItem="string" TValue="string" DataSource="@_signetsList">
<ComboBoxFieldSettings Value="ID" Text="Text"></ComboBoxFieldSettings>
</SfComboBox>
</EditTemplate>
</GridColumn>
<EditTemplate>
<SfDropDownList ID="ShipCountry" Value="@((context as Order).ShipCountry)" TValue="string" TItem="Countries" DataSource="@_infoSourceList">
<DropDownListEvents TValue="string"></DropDownListEvents>
<DropDownListFieldSettings Text="Name" Value="Name"></DropDownListFieldSettings>
</SfDropDownList>
</EditTemplate>
</GridColumn>
@code{
...
public string _signetValue = "BHTUKL";
public List<string> _signetsList = new List<string>() { "BHTUKL", "NGRTHU", "NHTJJIL" };
...
}
|
<SfGrid TValue="Order" @ref="grid" ID="Grid" DataSource="@_listSignetRapport" Toolbar="@(new List<string>() { "Add"})">
<GridEvents OnActionBegin="OnActionBegin" TValue="Order"></GridEvents>
...
</SfGrid>
@code{
public SfGrid<Order> grid { get; set; }
...
public async Task OnActionBegin(ActionEventArgs<Order> args)
{
switch (args.RequestType.ToString())
{
case "Save":
args.Cancel = true;
...
//Call the Refresh method after updating the vaulues to your DB
grid.Refresh();
break;
}
}
}
|
<style>
.e-grid .e-row .e-rowcell.e-selectionbackground {
background-color: yellow;
}
</style>
|
<SfButton @onclick="onclick">Select rows</SfButton>
<SfGrid TValue="Order" @ref="grid" ID="Grid" DataSource="@_listSignetRapport" Toolbar="@(new List<string>() { "Add"})">
<GridSelectionSettings Type="SelectionType.Multiple"></GridSelectionSettings>
...
</SfGrid>
<style>
.e-grid .e-row .e-rowcell.e-selectionbackground {
background-color: red;
}
</style>
@code{
...
public void onclick()
{
List<int> Index = new List<int>() { 1,2 };
grid.SelectRows(Index); //need also to color it to red
}
...
}
|
<SfGrid TValue="Order" AllowPaging="true" DataSource="@Orders" Toolbar="@( new List<string> { "Add","Edit","Delete","Update","Cancel" })" Locale="es" >
...
</SfGrid>
|
[Startup.cs]
namespace BlazorApp1
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddSyncfusionBlazor();
services.AddLocalization(options => options.ResourcesPath = "Resources");
services.Configure<RequestLocalizationOptions>(options =>
{
// // define the list of cultures your app will support
var supportedCultures = new List<CultureInfo>()
{
new CultureInfo("en-US"),
new CultureInfo("es")
};
// set the default culture
options.DefaultRequestCulture = new RequestCulture("es");
options.SupportedCultures = supportedCultures;
options.SupportedUICultures = supportedCultures;
options.RequestCultureProviders = new List<IRequestCultureProvider>() {
new QueryStringRequestCultureProvider()
};
});
services.AddRazorPages();
services.AddServerSideBlazor();
services.AddSingleton(typeof(ISyncfusionStringLocalizer), typeof(SampleLocalizer));
services.AddSingleton<WeatherForecastService>();
...
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseRequestLocalization();
...
}
}
}
|
[SampleLocalizer.cs]
public class SampleLocalizer : ISyncfusionStringLocalizer
{
public string Get(string key)
{
return this.Manager.GetString(key);
}
public System.Resources.ResourceManager Manager
{
get
{
return blazordatagrid.Resources.SyncfusionBlazorLocale.ResourceManager;
}
}
}
|
<style>
.e-grid .e-headercell {
color:red;
background-color:deepskyblue;
}
</style>
|
<SfGrid TValue="Order" @ref="grid" ID="Grid" DataSource="@_listSignetRapport" Toolbar="@(new List<string>() { "Add"})">
<GridSelectionSettings Type="SelectionType.Multiple"></GridSelectionSettings>
<GridEvents HeaderCellInfo="HeaderCellInfo" TValue="Order"></GridEvents>
...
</SfGrid>
<style>
.e-grid .e-row .e-rowcell.e-selectionbackground {
background-color: red;
}
.e-grid .orderidcss {
color: blue;
background-color: greenyellow;
}
</style>
@code{
...
public void HeaderCellInfo(HeaderCellInfoEventArgs args)
{
var ColDetails = JsonConvert.DeserializeObject<Dictionary<string, object>>(args.Cell.ToString());
foreach (var a in ColDetails)
{
var ColumnField = new GridColumn();
if (a.Key == "column")
{
ColumnField = JsonConvert.DeserializeObject<GridColumn>(a.Value.ToString());
}
if (ColumnField.Field == "OrderID")
{
args.Node.AddClass(new string[] { "orderidcss" }); //Based on a particular header cell add the css to apply style for a particular header cell
}
}
}
}
|
<SfButton @onclick="onclick">Select rows</SfButton>
<SfGrid TValue="Order" @ref="grid" ID="GridInstance" DataSource="@_listSignetRapport" @attributes="@GridAttributes" Toolbar="@(new List<string>() { "Add"})">
<GridSelectionSettings Type="SelectionType.Multiple"></GridSelectionSettings>
<GridEvents TValue="Order" RowSelecting="RowSelecting" RowSelected="RowSelected"></GridEvents>
...
</SfGrid>
<style>
.e-grid[data-selection="custom"] .e-rowcell.e-selectionbackground { //use css selector to apply style for selection
background-color: red !important;
}
</style>
@code{
private Dictionary<string, object> GridAttributes { get; set; } = new Dictionary<string, object>();
ObservableCollection<Order> _listSignetRapport { get; set; }
public bool flag = false;
public bool RowSelectedFlag = false;
...
public void onclick()
{
if (GridAttributes.Count == 0) //set the attribute for Grid’s div element
{
GridAttributes.Add("data-selection", "custom");
}
else
{
GridAttributes["data-selection"] = "custom";
}
List<int> Index = new List<int>() { 1,2 };
RowSelectedFlag = true; //set the flag to indicate selection is done using button click
grid.SelectRows(Index);
}
public void RowSelecting(RowSelectingEventArgs<Order> args) //in this event, we will remove the attribute when select a record by mouse click
{
if (flag)
{
GridAttributes["data-selection"]= "";
flag = false;
}
}
public void RowSelected(RowSelectEventArgs<Order> args) //in this event, we will set flags for removing the attribute, when perform select by button click
{
if (RowSelectedFlag)
{
flag = true;
RowSelectedFlag = false;
}
}
...
}
|
<data name="DropDownList_NoRecordsTemplate" xml:space="preserve">
<value>Aucun enregistrement trouvé</value>
</data>
|
<GridColumn HeaderText="" Width="150" CustomAttributes="@(new { @class="commandcss"})">
<GridCommandColumns>
<GridCommandColumn Type="CommandButtonType.Edit" ButtonOption="@(new CommandButtonOptions() { IconCss = "e-icons e-edit", CssClass = "e-flat" })"></GridCommandColumn>
...
</GridCommandColumns>
</GridColumn>
<style>
.e-grid .commandcss {
color: blue;
background-color: greenyellow;
}
</style>
|
<style>
/*Below styles apply color for toolbar area in Grid*/
.e-grid .e-toolbar {
background-color: blue;
}
.e-grid .e-toolbar-items {
background-color: blue;
}
/*Below styles apply color for toolbar buttons which are enabled state*/
.e-grid .e-toolbar-items .e-tbar-btn {
background-color: blue;
}
.e-grid .e-toolbar-items .e-tbar-btn .e-btn-icon {
color: white;
}
.e-grid .e-toolbar-items .e-tbar-btn .e-tbar-btn-text {
color:white;
}
/*Below styles apply color for toolbar buttons with overlay(disabled)*/
.e-grid .e-toolbar-items .e-toolbar-item.e-overlay .e-tbar-btn {
background-color: blue;
}
.e-grid .e-toolbar-items .e-toolbar-item.e-overlay .e-tbar-btn .e-btn-icon {
color: white;
}
.e-grid .e-toolbar-items .e-toolbar-item.e-overlay .e-tbar-btn .e-tbar-btn-text {
color: white;
}
.e-toolbar .e-toolbar-items .e-toolbar-item.e-overlay {
background-color: blue;
}
</style>
|
<style>
...
.e-grid[data-selection="custom"] .e-row.e-editedrow .e-rowcell {
background-color: red !important;
}
...
</style> |
<GridEvents HeaderCellInfo="HeaderCellInfo" TValue="Order" RowSelecting="RowSelecting" RowDeselecting="RowDeselecting" RowSelected="RowSelected"></GridEvents>
List<int> ErrorRowIndex = new List<int>() { 1, 2 };
public void onclick()
{
grid.ClearRowSelection();
if (GridAttributes.Count == 0)
{
GridAttributes.Add("data-selection", "custom");
}
else
{
GridAttributes["data-selection"] = "custom";
}
ErrorRowIndex = new List<int>() { 1, 2 };
RowSelectedFlag = true;
grid.SelectRows(ErrorRowIndex); //need also to color it to red
}
public void RowDeselecting(RowDeselectEventArgs<Order> args)
{
if (ErrorRowIndex.Contains(Convert.ToInt32(args.RowIndex)) && flag)
{
args.Cancel = true;
}
}
public void RowSelecting(RowSelectingEventArgs<Order> args)
{
if (flag && !ErrorRowIndex.Contains(Convert.ToInt32(args.RowIndex)))
{
GridAttributes["data-selection"]= "";
flag = false;
}
}
public void RowSelected(RowSelectEventArgs<Order> args)
{
if (RowSelectedFlag)
{
flag = true;
RowSelectedFlag = false;
}
}
|
<SfButton @onclick="MarkError">ErrorMarker</SfButton>
<SfButton @onclick="RemoveError">RemoveError</SfButton>
<SfGrid TValue="Order" @ref="grid" ID="GridInstance" DataSource="@Orders" Toolbar="@(new List<string>() { "Add"})">
<GridEvents TValue="Order" RowDataBound="RowBound" ></GridEvents>
...
</SfGrid>
<style>
.error-row {
background-color: red;
}
</style>
@code{
public bool Markflag = false;
public void MarkError()
{
Markflag = true;
grid.Refresh();
}
public void RemoveError()
{
Markflag = false;
grid.Refresh();
}
public void RowBound(RowDataBoundEventArgs<Order> args)
{
if (Markflag && (args.Data.OrderID == 1001 || args.Data.OrderID == 1002))
{
args.Row.AddClass(new string[] { "error-row" });
}
}
}
|
.e-grid .e-columnheader .e-headercell {
color: white;
background-color: #0275d8;
}
|
@code{
public List<Order> Orders { get; set; }
public SfGrid<Order> grid { get; set; }
...
public void OnActionComplete(ActionEventArgs<Order> args)
{
if(args.RequestType.ToString() == "Save")
{
grid.SelectRow(0); //Select the corresponding row by passing the index value.
}
}
...
}
|
<DialogPositionData X="center" Y="top"></DialogPositionData>
|
protected async void ShowToastWithMessage()
{
_toastContent = string.Format("<li class=\"validation-message\">{0}</li>", "You have an error here!!");
await _toastObj.Hide();
await Task.Delay(100);
await _toastObj.Show();
}
|
.e-toast-container .e-toast:hover {
background-color: red;
} |
<EditTemplate>
<SfDropDownList @ref="dropinstance" TValue="int" TItem="Order" ...>
<DropDownListEvents Created="Created" TValue="int"></DropDownListEvents>
</SfDropDownList>
</EditTemplate>
</GridColumn>
SfDropDownList<int, Order> dropinstance;
...
public void Created()
{
dropinstance.FocusIn();
}
|
<SfGrid TValue="Order" @ref="grid" ID="GridInstance" DataSource="@Orders" Toolbar="@(new List<string>() { "Add"})">
<GridEditSettings AllowEditing="true" AllowDeleting="true" ... ShowDeleteConfirmDialog="false"></GridEditSettings>
<GridEvents TValue="Order" ... OnActionBegin="OnActionBegin" ></GridEvents>
...
</SfGrid>
<SfDialog @bind-Visible="@Visible" IsModal="true" Width="400px" ShowCloseIcon="true" CloseOnEscape="true">
...
</SfDialog>
@code{
...
public async Task OnActionBegin(ActionEventArgs<Order> args)
{
if (args.RequestType.ToString() == "Delete")
{
args.Cancel = true; //Cancel the default delete action and do the delete action in Oui button click
Visible = true; //Display your custom dialog
}
}
private Boolean Visible = false;
...
}
|
<EditTemplate>
<SfComboBox @ref="comboinstance" ID="NomSignet" ... TItem="string" TValue="string" >
<ComboBoxEvents Created="Created" TValue="string"></ComboBoxEvents>
</SfComboBox>
</EditTemplate>
SfComboBox<string, string> comboinstance;
public void Created()
{
comboinstance.FocusIn();
}
|