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

[Solved] Create custom edit templates

1 Answer 309 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.
Waliaula
Top achievements
Rank 1
Waliaula asked on 17 Sep 2010, 05:58 AM
Is it possible for one to create a custom edit form template to use for in-form and popup form instead of using the one offered by the grid. Or even customize it further i.e. have two columns of controls instead of one like it has right now?

1 Answer, 1 is accepted

Sort by
0
Joan Vilariño
Top achievements
Rank 2
answered on 17 Sep 2010, 11:02 AM

Hi Waliaula.

I've "tricked" the telerik's grid placing my own "commands" column and editing inside Telerik's window. I'll try to post a readable example.

You can use something like this to mimic Telerik's grid command window:

col.Bound(o => o.Id).ClientTemplate("<a class='t-grid-action t-button t-state-default btnEdit>Edit</a>"+
                         "<a class='t-grid-action t-button t-state-default btnDelete>Delete</a>")
                         .Title("Actions").Width(180);

Then you can react to the button click like this:

$('.btnEdit').live('click',function(e) {
    e.preventDefault();
    var myObj = $('#myGrid').data.('tGrid').dataItem($(e.target).closest('tr'));
    $.ajax({
        url:'/myController/myEditorPartialViewRenderer/' + myObj.Id,
        type: 'post',
        cache: false,
        success: function(data) {
            var popup =$.telerik.window.create({
                title:'Edit Item',
                modal:true,
                onClose: function(e) {
                        e.preventDefault();
                        popup.data('tWindow').destroy();   
                                 $('#myGrid').data('tGrid').rebind();     
                }
            });
            popup.find('.t-window-content').html(data);
            popup.center().open();
        }
    });
});

This javascript at the bottom of your view will open a window when someone clicks the Edit button (that mimics totally the telerik's command button) and will call the action 'myEditorPartialViewRenderer' to load the editor form inside a telerik window, passing the Id of your item to edit.

When the user closes the window (you must post and save your item in the Ok button you put inside or whatever) it will destroy it and reload the grid's data.

I hope this helops...

Cheers!!
Tags
Grid
Asked by
Waliaula
Top achievements
Rank 1
Answers by
Joan Vilariño
Top achievements
Rank 2
Share this question
or