Ticket T1084380
Visible to All Users

How to show a translated enum value in a custom CellDisplayTemplate

created 3 years ago (modified 3 years ago)

Hello,

I wrote the code below for the new blazor grid to set cell values wrapping. But it can't show the language translated values of objects like Enums in listviews. How can i do this?

Thank you.

C#
//.... foreach(var column in gridAdapter.GridDataColumnModels) { if (column.FieldName != "Customer" && column.FieldName != "Customer.UserName") { column.CellDisplayTemplate = CustomCellTemplate.Create(); } }
Razor
@using DevExpress.Blazor; @using DevExpress.ExpressApp.DC; <div class="d-block text-truncate" style="max-width: auto;"> @Context.DisplayText </div> @code { [Parameter] public GridDataColumnCellDisplayTemplateContext Context { get; set; } public static RenderFragment<GridDataColumnCellDisplayTemplateContext> Create() { return (GridDataColumnCellDisplayTemplateContext context) => @<CustomCellTemplate Context=@context />; } }

Answers approved by DevExpress Support

created 3 years ago (modified 2 years ago)

Hello Mete,

You can use the EnumDescriptor.GetCaption method to get a localized caption from an Enum value: EnumDescriptor Class.

Note that if you replace the default CellDisplayTemplate, this will override all features implemented in XAF Property Editors - e.g., the File Attachment module's file download links. I can see that you used a custom template only to add Bootstrap classes to grid cells. You can achieve the same result by implementing an appropriate CSS selector with styles from these classes. The following image shows how to find a selector that affects these styles in DxGrid:

Clipboard-File-3.png

Implement a selector with a higher specificity to override these styles. For example:

CSS
.main-content .dxbs-grid .dxbs-grid-table > tbody > tr > td { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }

Alternatively, wrap the default cell template into an element with the required classes:

C#
public class ListViewController1: ViewController<ListView> { protected override void OnViewControlsCreated() { base.OnViewControlsCreated(); DxGridListEditor gridListEditor = View.Editor as DxGridListEditor; if (gridListEditor != null) { foreach (var column in gridListEditor.GetGridAdapter().GridDataColumnModels) { if (column.FieldName != "Customer" && column.FieldName != "Customer.UserName") { var defaultTemplate = column.CellDisplayTemplate; column.CellDisplayTemplate = (GridDataColumnCellDisplayTemplateContext context) => builder => { builder.OpenElement(0, "div"); builder.AddAttribute(1, "class", "d-block text-truncate"); builder.AddContent<GridDataColumnCellDisplayTemplateContext>(2, defaultTemplate, context); builder.CloseElement(); }; } } } } }

If you find my answer helpful, please make this ticket visible to everyone. Thank you!

For more examples of using custom cell templates in XAF, refer to the following ticket: Xaf Blazor - How to use a custom cell template (HTML markup) in Grid List Editor.

    Show previous comments (1)
    Dennis Garavsky (DevExpress) 3 years ago

      Can we please make this ticket public for other XAFers?

        Of course, I would be glad if it helps others as well.

        Anatol (DevExpress) 3 years ago

          Thank you, Mete.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.