[CLOSED] How to : show the DisplayName attribute in column header?

  1. #1

    [CLOSED] How to : show the DisplayName attribute in column header?

    hello, i write a gridpanel in the razor view, and use Html.X().ColumnFor to display column.

    Column name displayed is not DisplayNameAttribute, but the Property name.

    How do I make it show DisplayName attribute in column header?

    Thank you.
    Last edited by Daniil; Jan 10, 2014 at 11:14 AM. Reason: [CLOSED]
  2. #2
    Hi @macroe,

    I am not sure we should treat the DisplayName attribute as a Column's header text.

    Please use the Column attribute.
    [Ext.Net.MVC.Column(Text = "Header Text")]
  3. #3
    Quote Originally Posted by Daniil View Post
    Hi @macroe,

    I am not sure we should treat the DisplayName attribute as a Column's header text.

    Please use the Column attribute.
    [Ext.Net.MVC.Column(Text = "Header Text")]
    Thanks, but how can I localize the header text?
  4. #4
    Hello!

    Quote Originally Posted by macroe View Post
    Thanks, but how can I localize the header text?
    If you mean localization using ResourceProvider, I'm afraid it is not possible right now.

    However, you can extend attributes to add this functionality. You can find examples in the Internet like this one: http://carrarini.blogspot.ca/2010/08...notations.html.
  5. #5
    Quote Originally Posted by Baidaly View Post
    Hello!



    If you mean localization using ResourceProvider, I'm afraid it is not possible right now.

    However, you can extend attributes to add this functionality. You can find examples in the Internet like this one: http://carrarini.blogspot.ca/2010/08...notations.html.

    Sorry, I'm not very good at English.

    But ,I have a BitResourceDisplayNameAttribute to localize displayname, it works fine in Html.X().TextField ,Html.X().Combobox() and so on, but not works in Column.


    And, happy new year~

        public class BitResourceDisplayNameAttribute : System.ComponentModel.DisplayNameAttribute, IModelAttribute
        {
            private string _resourceValue = string.Empty;
            //private bool _resourceValueRetrived;
    
            public BitResourceDisplayNameAttribute(string resourceKey)
                : base(resourceKey)
            {
                ResourceKey = resourceKey;
            }
    
            public string ResourceKey { get; set; }
    
            public override string DisplayName
            {
                get
                {
                    //do not cache resources because it causes issues when you have multiple languages
                    //if (!_resourceValueRetrived)
                    //{
                    var langId = EngineContext.Current.Resolve<IWorkContext>().WorkingLanguage.Id;
                        _resourceValue = EngineContext.Current
                            .Resolve<ILocalizationService>()
                            .GetResource(ResourceKey, langId, true, ResourceKey);
                    //    _resourceValueRetrived = true;
                    //}
                    return _resourceValue;
                }
            }
    
            public string Name
            {
                get { return "BitResourceDisplayName"; }
            }
        }
    Last edited by macroe; Jan 01, 2014 at 4:47 AM.
  6. #6
    We meant that you should extend Ext.Net.MVC.ColumnAttribute for Text localization
  7. #7
    Quote Originally Posted by Vladimir View Post
    We meant that you should extend Ext.Net.MVC.ColumnAttribute for Text localization
    oh, i get it ,thank you!

    and, i changed the source code Ext.Net\MVC\Ext\Grid\GridPanel.cs , 163 row to

    //column.Text = Regex.Replace(propertyMetadata.PropertyName, "([a-z])([A-Z])", "$1 $2");
                            if (!string.IsNullOrEmpty(propertyMetadata.DisplayName))
                            {
                                column.Text = propertyMetadata.DisplayName;
                            }
                            else
                            {
                                column.Text = Regex.Replace(propertyMetadata.PropertyName, "([a-z])([A-Z])", "$1 $2");
                            }
    it work fine!
    Last edited by Daniil; Jan 06, 2014 at 1:05 PM. Reason: Please use [CODE] tags
  8. #8
    A nice tweak! It has been committed to SVN in the revision #5601. It will go to the v2.5 release.
  9. #9
    Needs similar changes in other classes:
    http://forums.ext.net/showthread.php?30791

Similar Threads

  1. Replies: 1
    Last Post: Jan 14, 2015, 2:19 PM
  2. Replies: 0
    Last Post: Apr 19, 2012, 3:53 PM
  3. [CLOSED] Hide the column option(on click of column header) for treegrid
    By AnulekhaK in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Feb 01, 2012, 11:16 AM
  4. Replies: 1
    Last Post: Nov 24, 2011, 6:48 AM
  5. Replies: 1
    Last Post: Apr 22, 2009, 7:03 AM

Posting Permissions