Grid Yes/No Column

2 posts, 0 answers
  1. Decisive Computing
    Decisive Computing avatar
    17 posts
    Member since:
    Mar 2015

    Posted 21 May 2017 Link to this post

    Requirements

    Telerik Product and Version

    ASP.net AJAX 2017 R2

    Supported Browsers and Platforms

    Same as Telerik ASP.net AJAX

    Components/Widgets used (JS frameworks, etc.)

    RadGrid


    PROJECT DESCRIPTION 
    I find that my users do not like checkbox columns very much. I find that they much prefer a Yes/No to be displayed instead as well as being able to select Yes or No when editing. That is why I wrote the GridYesNoDropDownColumn. It's actually quite simple as shown below. I hope you find this as useful as I have!

    public class GridYesNoDropDownColumn : GridDropDownColumn
        {
            #region CTOR
     
            public GridYesNoDropDownColumn()
            {
                this.ColumnValidationSettings.RequiredFieldValidator.InitialValue = "*";
                this.ListTextField = "Value";
                this.ListValueField = "Key";
                this.DropDownControlType = GridDropDownColumnControlType.DropDownList;
            }
     
            #endregion // CTOR
     
     
            #region IMPLEMENTATION
     
     
            /// <summary>
            /// Sets the drop down list's data source
            /// </summary>
            /// <param name="inItem"></param>
            protected override void SetDropDownListDataSource(GridItem inItem)
            {
                GridDropDownColumnEditor editor = (GridDropDownColumnEditor)this.CurrentColumnEditor;
                Dictionary<bool?, string> data = new Dictionary<bool?, string>();
                if (this.EnableEmptyListItem)
                    data.Add(null, "");
                data.Add(true, "Yes");
                data.Add(false, "No");
                editor.DataSource = data;
                base.SetDropDownListDataSource(inItem);
            }
             
            #endregion // IMPLEMENTATION
        }
  2. Eyup
    Admin
    Eyup avatar
    3449 posts

    Posted 24 May 2017 Link to this post

    Hello,

    Thank you for sharing your specific approach with our community. I've updated your Telerik points as a token of gratitude.

    I just want to insert a general caveat here that using custom controls is beyond our support scope, even when they are inherited directly from Telerik controls:
    http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/inheritance/inheriting-grid-columns

    Another approach to achieve this requirement is to use a GridTemplateColumn:
    http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/columns/column-types#gridtemplatecolumn

    Regards,
    Eyup
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top