When filtering or editing a Grid with enum data, the Name property of their Display parameter is respected.
However, in the initial view mode of the Grid the Name property is not applied and the enum values are rendered regardless of whether or not their Display parameter has a Name property defined.
==========
ADMIN EDIT
==========
In the meantime, a workaround you might try is to create a custom method to check whether Display attribute is defined and get and display its Name property, otherwise display the Enum's member name.
You can then use a Template for the column that uses enum data, cast its context to the model you are using and invoke the method on the field containing the enum. The sample below demonstrates how you can achieve this.
@using System.ComponentModel.DataAnnotations
@using System.Reflection
<TelerikGrid Data=@MyData EditMode="@GridEditMode.Inline" Pageable="true" Height="500px"
OnUpdate="@UpdateHandler" FilterMode="@GridFilterMode.FilterRow">
<GridColumns>
<GridColumn Field=@nameof(SampleData.ID) Editable="false" Title="ID" />
<GridColumn Field=@nameof(SampleData.Name) Title="Name" />
<GridColumn Field=@nameof(SampleData.Role) Title="Position">
<Template>
@{
var currentEmployee = context as SampleData;
var currentRole = GetDisplayName(currentEmployee.Role);
}
@currentRole
</Template>
</GridColumn>
<GridCommandColumn>
<GridCommandButton Command="Save" Icon="save" ShowInEdit="true">Update</GridCommandButton>
<GridCommandButton Command="Edit" Icon="edit">Edit</GridCommandButton>
</GridCommandColumn>
</GridColumns>
</TelerikGrid>
@code {
//custom method to check whether Display attribute is defined and get and display its Name property, otherwise display the Enum's member name
public string GetDisplayName(Enum val)
{
return val.GetType()
.GetMember(val.ToString())
.FirstOrDefault()
?.GetCustomAttribute<DisplayAttribute>(false)
?.Name
?? val.ToString();
}
public void UpdateHandler(GridCommandEventArgs args)
{
SampleData item = (SampleData)args.Item;
//update the view-model
var index = MyData.FindIndex(i => i.ID == item.ID);
if (index != -1)
{
MyData[index] = item;
}
//perform actual data source operations here
}
//model and dummy data generation
public class SampleData
{
public int ID { get; set; }
public string Name { get; set; }
public Role Role { get; set; }
}
public enum Role
{
[Display(Name = "Manager")]
ManagerRole,
[Display(Name = "Employee")]
EmployeeRole,
[Display(Name = "Contractor")]
ContractorRole
}
public List<SampleData> MyData { get; set; }
protected override void OnInitialized()
{
MyData = new List<SampleData>();
for (int i = 0; i < 50; i++)
{
MyData.Add(new SampleData()
{
ID = i,
Name = "name " + i,
Role = (Role)(i % 3) // just some sample to populate initial values for the enum
});
}
}
}
If the TextArea component is used within an EditorTemplate of a grid column, edit mode is always closed upon hitting ENTER. The thing is that I'm using the TextArea to allow the user to input several lines. Upon Enter the user wants to move to a new line within the TextArea and not to finish the edit mode.
Regards,
René
---
ADMIN EDIT
For the time being I can offer using the popup editing or a custom external edit form (inline or popup).
Another workaround would be to stop the keydown event propagation so the grid/treelist cannot consume it and close the cell:
<TreeListColumn Field="EmailAddress" Width="220px">
<EditorTemplate>
@{
CurrentlyEditedEmployee = context as Employee;
<div @onkeydown:stopPropagation="true">
<TelerikTextArea @bind-Value="@CurrentlyEditedEmployee.EmailAddress"></TelerikTextArea>
</div>
}
</EditorTemplate>
</TreeListColumn>
It is possible that the grid might stop handling Enter when editor templates are present so you can use the events from the custom editor as desired to invoke the save operation. This could happen through the following request: https://feedback.telerik.com/blazor/1493770-ability-to-prevent-multiple-calls-of-async-updatehandler-when-pressing-enter-in-incell-edit-mode. With or without it, it is highly likely that the approach of preventing the event propagation is the correct one because the grid cannot know what the editor template contains and handle events differently based on that.
---
In many cases users need to be able to specify a number which is easily visualized using a horizontal slider.
This allows the user to easily move the point to their desired location.
It can be helpful to allow this to also be constrained using a forced range selection.
I have been trying to improve my Lighthouse score with Google and one of the items it is tagging is the "telerik-blazor.js" file. I have seen new practices where the JavaScript is imported as needed, see this article here from Microsoft.
Can you please consider this in the future?
===
Telerik edit: A possible workaround is to build the Telerik JavaScript file without some of the components that you don't need.
Hi
Passwords are not yet supported. There is a DataAnotations Datatype for that. So technically this is possible and should not be a big deal. Almost all apps have a password entry somewhere.
Example:
class LoginModel
{
[Required]
[Display(Name = "User Name")]
public string UserName { get; set; }
[Required]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
}
Annoying because then you have to do the form fields all manually because of the password.
Thanks for considering.
Best regards, Michael
Hi,
is it possible to add control of vertical timeline like this (https://antblazor.com/en-US/components/timeline) with extra features like:
I also attached image of what i build based on control from link above, I would like to implement something similar with Telerik.
Maybe you can recommend some other controls to replace it with?
Thank you :)
Greetings!
Since the focus events are natively supported by blazor, could they be implemented in the input controls? Workarounds via JS are possible but they create a lot of redundant and cluttered code around the code base. OnChange/ValueChange only fire when the value has changed. Though, we have a lot of scenarios where we need the focus events when a value did not change.
Unexpected scroll behaviour is seen after selecting an item in a DropDownList/Multiselect with a scroll mode set to virtualise. We are unable to easily scroll upwards using the scroll bar in the control or using a mouse/trackpad. The scroll position immediately snaps back to the selected item. Sometimes we are able 'escape' this by rapidly scrolling but this does not feel like intended behaviour.
Downward scrolling seems okay and using the keyboard arrow keys also seems unaffected. This is reproducible on the demo page: Blazor DropDownList - Virtualization - Telerik UI for Blazor and https://docs.telerik.com/blazor-ui/components/multiselect/virtualization.
Reproduction steps on Chrome:
Minimal reproducible example: Blazor MultiSelect - Virtualization - Telerik UI for Blazor
<input class="form-control" readonly="@(!EditMode)" type="text" @bind="@FormField.TextValue"/>
I couldn't find a way to change the default AnimationDuration of the combobox's popup. Personally, I find the default AnimationDuration set at 300ms way too high.
I'd like a way to change it either per-component, by setting animation properties on them when appropriate, or globally, by configuring it in Startup.cs or on TelerikRootComponent perhaps. I've no idea how this should work.
---
ADMIN EDIT
Here is a way to change the animation of the dropdown per component - through the PopupClass (note that the popup class may move to the topmost element of the popup in a future version, if this stops working, inspect the rendering to see where the custom class is and how to cascade through it):
<style>
.fast-animation.k-popup.k-reset {
transition-duration: 100ms !important;
}
.slow-animation.k-popup.k-reset {
transition-duration: 1000ms !important;
}
.no-animation.k-popup.k-reset {
transition: none !important;
}
</style>
<TelerikComboBox PopupClass="fast-animation"
Data="@myComboData"
TextField="MyTextField"
ValueField="MyValueField"
@bind-Value="selectedValue"
Placeholder="Fast animation"
ClearButton="true" Filterable="true">
</TelerikComboBox>
<TelerikDropDownList PopupClass="no-animation"
Data="@myComboData"
TextField="MyTextField"
ValueField="MyValueField"
@bind-Value="selectedValue"
DefaultText="No Animation">
</TelerikDropDownList>
<TelerikDatePicker PopupClass="slow-animation" @bind-Value="@SelectedDate"></TelerikDatePicker>
@code {
IEnumerable<MyDdlModel> myComboData = Enumerable.Range(1, 20).Select(x => new MyDdlModel { MyTextField = "item " + x, MyValueField = x });
DateTime SelectedDate { get; set; } = DateTime.Now;
int selectedValue { get; set; }
public class MyDdlModel
{
public int MyValueField { get; set; }
public string MyTextField { get; set; }
}
}
First of all, The team loves the product, and development is going 10x faster with a UI library with so many features.
But we're looking for making diagrams inside our application. Something like https://www.syncfusion.com/blazor-components/blazor-diagram
is it a feature currently in the backlog or is it possible to put it there?
That will make us possible to make a flowchart over what assets are connected to each other in our data center
The CSS classes used by Blazor UI are not documented. (I haven't looked outside the Blazor area, so maybe it's somewhere else in the docs? My team has no need for other Telerik products.) On a similar note, the Themes page in the documentation explains how to reference alternate themes like Bootstrap, but it doesn't explain how to actually use the classes, or how it integrates with the real Bootstrap CSS, which have many various useful, well-known utilities like margin and padding settings, which don't seem to be part of the Telerik theme support. (I'm an architect at a very large corporation, we do have one of those includes-everything DevCraft licenses, I just can't log in with that account.)