This is a migrated thread and some comments may be shown as answers.

[Solved] Hide column in popup

6 Answers 184 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ivan
Top achievements
Rank 1
Ivan asked on 05 Jun 2011, 11:28 AM
Hello,
I've tried to find a solution in other threads in here but didn't. My problem is that I cannot hide property from  inserting/editing popup window (I still wanna see column in grid). I've tried to use attribute ReadOnly (Model) and I also tried to set column to readonly (View). Everything works fine in InLine Mode but in popup mode I still see columns Created and Modified. Is there any way how to hide these two columns from popup?

Here is my model:
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System;
using System.Runtime.Serialization;
  
namespace Models
{
    /// <summary>
    /// Kraj - offline model
    /// </summary>
    public class RegionModel
    {
        #region Properties
        /// <summary>
        /// Gets or sets the id.
        /// </summary>
        /// <value>
        /// The id.
        /// </value>
        [ScaffoldColumn(false)]
        public int ID { get; set; }
        /// <summary>
        /// Gets or sets the name.
        /// </summary>
        /// <value>
        /// The name.
        /// </value>
        [Required]
        [DisplayName("Název")]
        public string Name { get; set; }
  
        /// <summary>
        /// Gets or sets the code.
        /// </summary>
        /// <value>
        /// The code.
        /// </value>
        [DisplayName("Kód")]
        public string Code { get; set; }
  
        /// <summary>
        /// Gets the created.
        /// </summary>
        [ReadOnly(true)]
        public DateTime Created { get; private set; }
  
        /// <summary>
        /// Gets the modified.
        /// </summary>
        [ReadOnly(true)]
        public DateTime Modified { get; private set; }
        #endregion
    }
}

Here is my View:
@{
    ViewBag.Title = "Index";
}
<h2>
    Index</h2>
<p>
    @( Html.Telerik().Grid<Models.RegionModel>()
        .Name("Grid")
        .DataKeys(keys => keys.Add(c => c.ID))
        .ToolBar(commands => commands.Insert().ButtonType(GridButtonType.Image))
        .DataBinding(dataBinding =>
        {
            dataBinding.Ajax()
            .Select("Select", "Region")
            .Insert("Create", "Region")
            .Update("Edit", "Region")
            .Delete("Delete", "Region");
        })
        .Columns(columns =>
        {
            columns.Bound(o => o.ID);
            columns.Bound(o => o.Name).Title("Název");
            columns.Bound(o => o.Code).Title("Kód");
            columns.Bound(o => o.Created).Title("VytvoÅ™ení objektu");
            columns.Bound(o => o.Modified).Title("Poslední uložená zmÄ›na");
            columns.Command(commands =>
            {
                commands.Edit().ButtonType(GridButtonType.Image);
                commands.Delete().ButtonType(GridButtonType.Image);
            }).Width(80).Title("Akce");
        })
        .Editable(editing => editing.Mode(GridEditMode.PopUp))
        .Sortable()
        .Pageable()
        .Filterable()
    )
</p>
    
Thank you for any suggestions, best regards Ivan.

6 Answers, 1 is accepted

Sort by
0
Pavel Vanek
Top achievements
Rank 1
answered on 06 Jun 2011, 07:16 AM
Hi,
we have exactly the same problem, any suggestions from you guys?
0
Atanas Korchev
Telerik team
answered on 09 Jun 2011, 07:56 AM
Hello,

 The troubleshooting help article explains this behavior. Long story short you need to decorate the property with [ScaffoldColumn(false)]. Then it will not be displayed in the grid and the popup editor.

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Pavel Vanek
Top achievements
Rank 1
answered on 09 Jun 2011, 08:06 AM
Yes but we need column in grid. As you can see [ScaffoldColomn] atributte is used above. We need to hide property in popup window.
0
Accepted
Atanas Korchev
Telerik team
answered on 09 Jun 2011, 08:43 AM
Hi Pavel Vanek,

The grid is using Html.EditorForModel for the popup form. There are three ways to hide a property from Html.EditorForModel:

  1. Use [ScaffoldColumn(false)]. This however would also hide the property from the grid columns.
  2. Create a custom editor template for your model and include only the properties of interest. This code library project shows how to do that.
  3. Use JavaScript to hide the unwanted input elements from the form. The OnEdit event should be used for that:
function onEdit(e) {
    //Replace UnitsInStock with the name of your property
    $(e.form).find("#UnitsInStock").closest(".editor-field").prev().andSelf().remove();
}


Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Yavuz
Top achievements
Rank 1
answered on 22 Mar 2012, 04:27 PM
Hi,
We have Same problem. I am not gonna write any script to remove column in popup. 
you have some methods like:
Column.Readonly()
Column.Visible()
Column.EditorTemplate()
Column.Title("ColumnName")
these method do not work on popup.
I want to use a single model for more than one view and in each one i need to use a different EditorTemplate so I am not going to put any annotation attribute   on the field.
for an instance in a view I need to show DateTimePicker and on the other one I need DatePicker.
so you should fix this problem by popup.
0
Atanas Korchev
Telerik team
answered on 23 Mar 2012, 04:25 PM
Hi,

 As I have said in my previous reply the grid is using Html.EditorForModel for the popup form.  The latter can be customized only in the three suggested ways.

All the best,
Atanas Korchev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
Tags
Grid
Asked by
Ivan
Top achievements
Rank 1
Answers by
Pavel Vanek
Top achievements
Rank 1
Atanas Korchev
Telerik team
Yavuz
Top achievements
Rank 1
Share this question
or