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

[Solved] Grid in popupmode makes readonly editable

3 Answers 185 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
william
Top achievements
Rank 1
william asked on 13 Jul 2011, 04:38 PM
Hi All,

Please find my ViewModel code below.
@(Html.Telerik().Grid(Model.Covers)
      .Name("risksGrid")
      .Sortable()
      .DataKeys(keys => keys.Add(r => r.Id))
      .DataBinding(dataBinding =>
      {
          dataBinding.Ajax()
                    .Update("_SaveAjaxEditing", "Grid");
      })
      .Columns(columns =>
              {
                  columns.Command(command =>
                      {
                          command.Edit();
                      });
                  columns.Bound(r => r.Name).Title("Cover");
                  columns.Bound(r => r.SumInsured);
                  columns.Bound(r => r.Rate);
                  columns.Bound(r => r.Excess);
                  columns.Bound(r => r.IncreasedXSDiscount);
                  columns.Bound(r => r.UseDiscount);
                  columns.Bound(r => r.TechnicalPrice).ReadOnly();
              })
      .Editable(editing => editing.Mode(GridEditMode.PopUp))
      .RowAction(row =>
      {
          if (row.IsAlternate) { row.HtmlAttributes["style"] = "background:aliceblue;"; }
      })
 
    )

The problem here is that when I press my Edit button and a record flips into the popup, My TechnicalPrice that I want as readonly as this is a calculated column and the ID that is the primary key both become editable. How do I stop these becoming editable in the popup?

3 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 14 Jul 2011, 09:17 AM
Hi William, 
This is a well known limitation caused by Html.EditorForModel which the grid uses internally to display the popup edit form. Html.EditorForModel is not aware that a column is readonly and displays all public properties of the model.

A few solutions are possible
  1. Use a inline editing mode.
  2. Decorate the readonly property with [ScaffoldColumn(false)]. Then it would be hidden from the edit form and the grid itself.
  3. Create an editor template for your model and exclude the readonly property.
  4. Use JavaScript to hide the readonly property from the edit form. You can use the OnEdit event to do that.
Regards,
Atanas Korchev
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Omar
Top achievements
Rank 1
answered on 28 Jul 2011, 02:56 AM
I tried using your approach to get around the readonly property in popup mode but when using the service binding, the values of the disabled property is not posted on the "value" object.

 function Grid_onEdit(e) {
           
            if (e.mode == 'edit') {
                $(e.form).find('#PersonID').attr('disabled','disabled');
          
            }

}
0
Deepika
Top achievements
Rank 1
answered on 25 Jan 2013, 05:45 AM
Hi,

I am also facing the same problem.

After doing disable for field, that field value i am not able to get on controller. Instead it give me null for the field EmpID which i had disabled in popup edit mode.

Any help or suggestion for this??

Is there any way to do this? Is it supportable??

Please reply.
Tags
General Discussions
Asked by
william
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Omar
Top achievements
Rank 1
Deepika
Top achievements
Rank 1
Share this question
or