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

Grid Add/Update field display...

2 Answers 189 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dennis
Top achievements
Rank 1
Dennis asked on 15 Jul 2012, 05:13 PM

How can I change the fields that display for an Add/Update? For an add I need to have 4 fields display and for an edit I need to only display 2. I tried creating a template usercontrol but it is showing up for both an add/update. I tried modifying the viewmodel and that is applying the changes to both the add/update also.

Grid:

@(Html.Kendo().Grid(Model)
        .Name("CodeManager")
    .Columns(columns =>
    {       
        columns.Bound(p => p.CodeID);
        columns.Bound(p => p.Status);
        columns.Command(command => { command.Edit(); }).Width(200);
     
    })
    .ToolBar(toolBar => toolBar.Create())
    .Editable(editable => editable.Mode(GridEditMode.PopUp)) 
    .Sortable()
    .Scrollable()
    .Groupable()
    .Pageable()
    .Filterable()
    .DataSource(dataSource => dataSource   
        .Ajax()
        .Events(events => events.Error("error_handler"))
        .ServerOperation(false)
            .Model(model =>
            {
                model.Id(p => p.CodeID);
                model.Field(p => p.CodeID).Editable(false);
                model.Field(p => p.Title).Editable(false);
            })
                 //.Read(read => read.Action("GetPersons", "CodeManager", new { classifications = @ViewBag.SelectedCatgory }))
                    .Update(update => update.Action("EditingCustom_Update", "CodeManager"))
                        .Create(update => update.Action("EditingCustom_Update", "CodeManager"))     
        )
            .Editable(ed => ed.Mode(GridEditMode.PopUp).TemplateName("_CodeEditor"))    
        )

Control:

public ActionResult Index(string classifications = "")
        {
            ViewData["Category"] = classifications;
            ViewData["Classifications"] = new SelectList(Classifications.List, "ClassificationText", "ClassificationText", classifications);
            var codModels = new List<CodeModel>();
            ViewBag.SelectedCatgory = classifications ?? "Type";
 
            if (Request.HttpMethod == "POST")
            {
                var model = _codeRepository.Search(classifications).ToModel();
                return View(model);
            }
 
            return View(codModels);
        }

Model:

blic class CodeModel
    {
        public string CodeID { get; set; }
 
        public string Title { get; set; }
 
        public string Status { get; set; }
 
        public bool Active { get; set; }
 
        public string Category { get; set; }
 
        public int UserID { get; set; }
 
    }




Thanks
Dennis

2 Answers, 1 is accepted

Sort by
0
Accepted
Iliana Dyankova
Telerik team
answered on 18 Jul 2012, 12:56 PM
Hi Dennis,

I am afraid the described functionality is not supported in Kendo UI Grid - both of the actions ( Add and Update) are treated as an edit operations and it is not possible to set different templates for them.

Regards,
Iliana Nikolova
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
IsmiKin
Top achievements
Rank 1
answered on 17 Aug 2012, 03:36 PM
Hi Dennis,

I've been using Kendo few months and today I just had the same problem that you. I use the javascript library, not the ASP, but I'm sure that is equivalent.

For do that you want, you must use the template for the window popup.

editable:{
    mode:"popup",
    template: kendo.template($("#templateCrearUsuario").html())
}

If you need an example, you can see it:
 http://www.kendoui.com/ClientsFiles/361804_popup-template-example.zip

I try to make a "patch" for edit event and it works. I hope that for you too.

edit: function(e){                                             
            if(e.model.idUsuario==null)
                $(".noEditableCampos").show()
            else
                $(".noEditableCampos").hide();
           }

I put the fields that I dont want to show when "Add" event in a div class ("noEditableCampos") and I detect if the id of the Model is filled, if it exists, is a Edit event, otherwise is Add event.

I hope it will be helpful for your case.

Regards, IsmiKin.
Tags
Grid
Asked by
Dennis
Top achievements
Rank 1
Answers by
Iliana Dyankova
Telerik team
IsmiKin
Top achievements
Rank 1
Share this question
or