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

Grid and Custom Templates

2 Answers 116 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gaetano
Top achievements
Rank 1
Gaetano asked on 20 May 2014, 09:36 AM
Hi guys, I have a couple of question regarding custom templates inside a grid.

Simpliest of all: Is it possible to have a single save button for add action without enabling edit mode?
In other words, I'd like to allow add and delete from my grid; not edit.
and I'd like to save after each add.
If I don't define the edit action (and edit transport url) I can't see any save button...
Am I doing something wrong??

now for the main question...
First of all I have to say that I'm using EF and I set it so that foreing keys are not included in the model to keep it simple and clean
(istead of having a int foireign_key_id and a class foreign_class, I just have the class in my model)

now I have a view to edit a model; this model has some list in it..
public int ID { get; set; }
        public string NAME { get; set; }
        public string DESCRIPTION { get; set; }
     
        public virtual ICollection<OBJECT_ACCESS_T006> OBJECT_ACCESS_T006 { get; set; }
        public virtual ICollection<ROLE_FUNCTION_T010> ROLE_FUNCTION_T010 { get; set; }
        public virtual ICollection<USER_ROLE_T007> USER_ROLE_T007 { get; set; }

I'm working with User_Role list...
in my view I normally edit the first two fields and then I user a grid for the list..like this.

@(Html.Kendo().Grid<ROLE_FUNCTION_T010>(Model.ROLE_FUNCTION_T010)
                .Name("Grid")
                .ToolBar(commands => { commands.Create().Text(AcsViewRes.BtnNewFunct); })
                .Columns(columns =>
                {
                    columns.Bound(c => c.ID).Visible(false);
                    columns.ForeignKey("FUNCTION_T008", ViewBag.FunctionsList).ClientTemplate("#: data.FUNCTION_T008 ? FUNCTION_T008.NAME : '" + "empty" + "'#");
                    columns.Command(command => { command.Destroy().Text(AcsViewRes.SaveDestroy); command.Edit(); });
                 
                })
                .Pageable()
                .Sortable()
                .Filterable()
                .Editable(mode => mode.Mode(GridEditMode.InLine))
                .DataSource(dataSource => dataSource
                    .Ajax()
                    .PageSize(5)
                    .ServerOperation(false)
                    .Model(model =>
                    {
                        model.Id(v => v.ID);
                        model.Field(v => v.FUNCTION_T008).DefaultValue(ViewBag.DefaultFunction);
                    })
                    .Update(r => r.Action("LinkFunction", "Function"))
                    .Create(r => r.Action("LinkFunction", "Function"))
                    .Destroy(r => r.Action("RemoveFunction", "Function"))
                 )
            )

(as you can see from this code, the first question is related to this grid)
anyway, ma sub model (USER_ROLE_T007) is:

[Key]
        public int ID;
 
        [UIHint("FunctionDropDownTemplate")]
        public FUNCTION_T008 FUNCTION_T008;
 

@model FUNCTION_T008
 
@(
    Html.DropDownList(string.Empty, ViewBag.FunctionsList as SelectList)
)
    
            (from controller: ViewBag.FunctionsList = new SelectList(functions, "ID", "NAME");)

now the problem is that, when I save the function property is empty...
I know how to do it using the foreign key Id...I did it before, but I'd like to keep the model without them..
so, my goal is to have this list of functions which the user can add or remove (actually is link and unlink), and on add user is prompt with a drop down list conteining all functions.

is that possible?

Thanks
Fabio

2 Answers, 1 is accepted

Sort by
0
Accepted
Petur Subev
Telerik team
answered on 22 May 2014, 11:44 AM
Hello Fabio,

You can have a single edit button which on click invokes the dataSource.sync method (this is what the save changes button do for batch editing mode).

I see no problem to make your Grid only inserting/deleting records (you just omit the update configuration of the dataSource and you miss the edit button). Regarding the automatic save after each change you can consider enabling the autoSync feature of the dataSource:

http://docs.telerik.com/kendo-ui/api/framework/datasource#configuration-autoSync

Indeed if you are using InLine editing mode then in order to create the cancel/update buttons you have to declare an edit button. You can hide the edit buttons with css (and you can enter some URL just to avoid the exception that you will get because of missing update transport configuration).

e.g.

http://trykendoui.telerik.com/@pesho/AFeP

As for the main question, you are trying to edit nested objects with the parent Grid bound to the root model? Please notice that such nested editing has just basic support as demonstrated in this online demo:

http://demos.telerik.com/kendo-ui/web/grid/editing-custom.html

This is why we suggest to use hierarchy of Grids instead like demonstrated in this code library:

http://www.telerik.com/support/code-library/grid-ajax-hierarchy-editing

Kind Regards,
Petur Subev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Gaetano
Top achievements
Rank 1
answered on 22 May 2014, 01:28 PM
Hi Petur,
thanks for your reply...

the first thing i suppose solves my question,
regarding the second..I hope you'd enhance  nested object editing in future releases

thanks
fabio
Tags
Grid
Asked by
Gaetano
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Gaetano
Top achievements
Rank 1
Share this question
or