Hi,
In the DataGrid component, only the Rowselected event occurs when we use the RowSelected and ContextMenuOpen events.
I want to enable or disable the controls I designed per click on each row of the Datagrid, and I also need the ContextMenu.
Thank you
Hi Jeevakanth Palaniappan,
Share us the Syncfusion NuGet version details.
I have downloaded latest trial version from Nuget
Share us more information on the problem you are facing
In the Datagrid Toolbar, I needed to set styles such as icons, titles, fonts, text colors, background colors, etc., which apparently had some limitations, so I created the my toolbar. The buttons in the my toolbar must be activated or deactivated based on the selected row. On the other hand, I use the context menu for other purposes.
Thank you for the sample sent, and this sample caused me to change the source code as follows, and this method apparently fixed the bug.
1-Source Code:
<GridEvents RowSelected="RowSelected" TValue="Users"></GridEvents>
<GridEvents ContextMenuOpen="ContextMenuOpened" TValue="Users"></GridEvents>
<GridEvents ContextMenuItemClicked="ContextMenuItemClickedHandler" TValue="Users"></GridEvents>
2-Modified source code:
<GridEvents RowSelected="RowSelected" ContextMenuOpen="ContextMenuOpened" ContextMenuItemClicked="ContextMenuItemClickedHandler" TValue="Global_Users"></GridEvents>
For example, in the last sample I checked, I put a DataGrid with search toolbax, but I encountered this error when searching.
blazor.webassembly.js:1 crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object.
..
Thank you
Hi Jeevakanth Palaniappan,
I spent a lot of time searching for error in the Datagrid and found the cause of the error. I had made the data source one of the database models that was related to other models. I used DTO for data source for testing and the bug was fixed. Is it not possible to use models related to other models as data sources?
Another question is that When a user uses theme High Contrast in Windows, when he selects the Datagrid row, there is no symbol indicating the row selected by the user. For example, in some softwares, a more colorful border is placed around the selected row or the background color of the selected row changes.
Another question is that I used the contextmenu in the Datagrid component and added a Custom item. Is it not possible to style items? For example, change the color of the icon.
Thank you for posting
|
<SfGrid Toolbar=@(new List<string>(){"Search"}) DataSource="@Orders" AllowSorting="true" AllowPaging="true" AllowExcelExport="true" AllowPdfExport="true" ContextMenuItems="@(new List<Object>() { "Copy", new ContextMenuItemModel { Text = "Copy with headers", Target = ".e-content", Id = "copywithheader" } })">
<style>
#copywithheader{
background-color: blue;
}
</style>
|
|
<head>
<link rel='nofollow' href="_content/Syncfusion.Blazor/styles/highcontrast.css" rel="stylesheet" />
</head> |
Hi Jeevakanth Palaniappan,
We would like to inform you that the grid is a strongly typed component so you have to use the same model for both datasource and gridcolumn fields.
Yes you are right
I checked the link. Is it possible to change the color of the icon (example: IconCss="fa fa-plus ")?
Thank you so much .
I saw a case in Microsoft Excel . In Excel software, when the Windows theme is high contrast, it puts a border for the selected cell. It would be great if we could have such a feature in the Datagrid.
|
<style>
span.e-menu-icon.e-icons.e-copy{
color: blue;
}
</style> |
Hi Jeevakanth Palaniappan,
In the last answer:
We would like to inform you that based on SelectionMode, the row/cell will be selected in the grid and if you navigate the cells, then the focus will be set to the corresponding cells like a box. So we suggest you to use any of the below suggestions based on your scenario.
I checked the suggested items, but unfortunately these items in the case that Windows user is in high contrast mode and the user selects a cell or row, there is no symbol such as border or background, etc. that the user can understand which row or cell he has selected Is.
Thank you
Hi Jeevakanth Palaniappan,
Yes, you are right and thank you for your time. The point I have to make is that we can not ask the user to change the browser settings. I thought it could be done without browser settings.
Is there a row header for the data grid to display the row number on? If this feature exists, we can give a special style to the row number per user click on a specific row, such as under row, etc., so that the user notices the clicked row.
Thank you.
Hi Jeevakanth Palaniappan,
Yes you are right. Do you think that the way I suggested is not appropriate? Forget the style method
After the user selects a row, place a character like * in the row header that represents the selected row. A similar method is to add a checkbox column. User By selecting a row we make the value of the same row true
Thank you
Hi Jeevakanth Palaniappan,
very good. Unfortunately, I did not see this feature. In the grid, I want the user to select a maximum of one row. I used the following settings, but the user can select more than one row by clicking on the checkboxes . Also, the user can not select more than one row with the mouse by holding down the ctrl key.
<GridSelectionSettings CheckboxOnly="false" PersistSelection="false" Mode="SelectionMode.Row" CheckboxMode="CheckboxSelectionType.ResetOnRowClick" EnableSimpleMultiRowSelection="false" Type="Syncfusion.Blazor.Grids.SelectionType.Single" ></GridSelectionSettings>
Thank you
|
@using Syncfusion.Blazor.Grids
<SfGrid @ref="Grid" DataSource="@Orders" AllowSelection="true" AllowPaging="true">
<GridSelectionSettings Mode="SelectionMode.Row"
CheckboxMode="CheckboxSelectionType.ResetOnRowClick"
Type="Syncfusion.Blazor.Grids.SelectionType.Single" ></GridSelectionSettings>
<GridEvents RowSelecting="RowSelectingHandler" TValue="Order"></GridEvents>
<GridColumns>
<GridColumn Type="ColumnType.CheckBox" Width="50"></GridColumn>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" Format="d" Type="ColumnType.Date" TextAlign="TextAlign.Right" Width="130"></GridColumn>
<GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn>
</GridColumns>
</SfGrid>
@code{
public List<Order> Orders { get; set; }
SfGrid<Order> Grid { get; set; }
public async Task RowSelectingHandler(RowSelectingEventArgs<Order> args)
{
await Grid.ClearSelectionAsync();
}
protected override void OnInitialized()
{
Orders = Enumerable.Range(1, 75).Select(x => new Order()
{
OrderID = 1000 + x,
CustomerID = (new string[] { "ALFKI", "ANANTR", "ANTON", "BLONP", "BOLID" })[new Random().Next(5)],
Freight = 2.1 * x,
OrderDate = DateTime.Now.AddDays(-x),
}).ToList();
}
public class Order {
public int? OrderID { get; set; }
public string CustomerID { get; set; }
public DateTime? OrderDate { get; set; }
public double? Freight { get; set; }
}
} |
Hi Jeevakanth Palaniappan,
Thank you for the code you provided. The bug was fixed. There is a small error. When the user clicks on the checkbox in the column header, it is possible to select all rows.
Thank you
Hi Jeevakanth Palaniappan,
Thank you for the video you provided. Is it not possible to prevent the selection of all rows? For example, hide or disable the checkbox header so that not all rows can be selected
Thank you
|
@using Syncfusion.Blazor.Grids
<SfGrid @ref="Grid" DataSource="@Orders" AllowSelection="true" AllowPaging="true">
<GridSelectionSettings Mode="SelectionMode.Row"
CheckboxMode="CheckboxSelectionType.ResetOnRowClick"
Type="Syncfusion.Blazor.Grids.SelectionType.Single" ></GridSelectionSettings>
<GridEvents RowSelecting="RowSelectingHandler" TValue="Order"></GridEvents>
<GridColumns>
<GridColumn Type="ColumnType.CheckBox" Width="50">
<HeaderTemplate>
</HeaderTemplate>
</GridColumn>
</GridColumns>
</SfGrid> |
Hi Jeevakanth Palaniappan,
I upgraded to version 20.1.0.56 , but despite the highlighted lines below, the data is no longer displayed in the DataGrid , and when I delete these lines, the data is displayed.
<GridColumn Type="ColumnType.CheckBox" Width="50">
@foreach (var col in lstSource)
{
//add column
}
Hi Sarah,
Thanks for the update.
We have checked your query and we are quite unclear about the exact issue you are facing. So kindly share the below kindly share the below details to validate the issue further from our end.
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/BlazorApp11956053010.zip
The above-requested details will be very helpful for us to validate the reported query at our end and provide the solution as early as possible.
Regards,
Monisha