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

Columns For Editing...

3 Answers 80 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.
Dennis
Top achievements
Rank 1
Dennis asked on 11 Jul 2012, 07:31 PM
I am following the example given for editing a record. My problem is that I don't want all the column to appear in the edit popup form. I see you set [ScaffoldColumn(false)] on a field and it will not show. The problem is I have 8 fields and I only want 2 to be editable. If I set the other 6 as [ScaffoldColumn(false)] then my grid will also hide them. How do I only display 2 (or however many) fields in my popup from the model class?

Thanks
Dennis

3 Answers, 1 is accepted

Sort by
0
Pedro
Top achievements
Rank 2
answered on 13 Jul 2012, 12:26 PM
I believe one of the ways is to add .remove() with jquery to the fields you want hidden.
0
Dennis
Top achievements
Rank 1
answered on 13 Jul 2012, 02:48 PM
Is there any way you can give me an example? I'll include my code so you can see what I have so far and how I would incorporate that. I really like Telerik and I'm trying to re-write an app for a proof of concept but if something as trivial as update/delete is this complicate the company will not invest in this product. Nobody seems to have an answer. I just can't believe I'm the only one who has faced this issue. I know the fields that you edit are not the same fields that you insert in any application.
 
Model:
 
public class CodeModel
   {
       [MaxLength(2)]
       [DisplayName("Code ID")]
       [UIHint("Codes"), Required]
       public string CodeID { get; set; }
 
       [HiddenInput(DisplayValue = false)]
       public string Title { get; set; }
 
       [HiddenInput(DisplayValue = false)]
       public string Status { get; set; }
 
       public bool Active { get; set; }
 
       [HiddenInput(DisplayValue = false)]
       public string Category { get; set; }
 
       [DisplayName("User ID")]
       [ScaffoldColumn(false)]
       public int UserID { get; set; }
 
   }

Grid:
@(Html.Telerik().Grid<hrmsMVC.Areas.HRMS.Models.CodeModel>()
        .Name("CodeManager")
            .DataKeys(keys =>
            {
                keys.Add(c => c.CodeID);
            })
            .ToolBar(commands => commands.Insert().ButtonType(GridButtonType.ImageAndText).ImageHtmlAttributes(new { style = "margin-left:0" }))
            .DataBinding(dataBinding =>
            {
                dataBinding.Ajax()
                    .Select("_Filtering", "CodeManager", new { classifications = @ViewBag.SelectedCatgory })
                    .Update("_SaveAjaxEditing", "codeManager", new { classifications = @ViewBag.SelectedCatgory })
                    .Insert("_InsertAjaxEditing", "CodeManager", new { classifications = @ViewBag.SelectedCatgory });
            })
        .Columns(columns =>
        {
 
            columns.Bound(o => o.CodeID).Width(120);
            columns.Bound(o => o.Title).Width(200);
            columns.Bound(o => o.Active).ClientTemplate("<input type='checkbox' disabled='disabled' name='Active' <#=Active ? checked='checked' : '' #> />").Width(120);
            columns.Command(commands =>
            {
                commands.Edit().ButtonType(GridButtonType.ImageAndText);
            }).Width(180).Title("Commands");
 
        })
            .Editable(editing => editing.Mode(GridEditMode.InForm).InsertRowPosition(GridInsertRowPosition.Top))
            .Sortable(sorting => sorting
            .SortMode(GridSortMode.SingleColumn)
            .AllowUnsort(true)
            .OrderBy(order =>
                {
                    order.Add(o => o.CodeID);
                })
             )
             .Pageable()
                 .Resizable(resizing => resizing.Columns(true))
            .Filterable()
                
        )

  
0
Pedro
Top achievements
Rank 2
answered on 13 Jul 2012, 03:34 PM
The only way that i have been able to hide or disable fields in the InForm editing is to use jQuery.

Here is a sample code of something that i did.

$('#TotalWeight').attr('disabled', 'disabled');
 
$('.t-grid-update').click(function () {
    $('#TotalWeight').removeAttr('disabled');
});

Pedro
Tags
Grid
Asked by
Dennis
Top achievements
Rank 1
Answers by
Pedro
Top achievements
Rank 2
Dennis
Top achievements
Rank 1
Share this question
or