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

[Solved] editable grid in editable grid

1 Answer 103 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.
Derk-Jan Sevink
Top achievements
Rank 1
Derk-Jan Sevink asked on 08 Apr 2011, 04:22 PM
i'm trying to build a page with an editable grid in an editable grid.

view:
@(Html.Telerik().Grid<ContactModel>()
    .Name("Contacts")
    .Localizable("nl-NL")
    .DataKeys(keys => { keys.Add(c => c.ContactId); })
    .ToolBar(commands => commands.Insert().ButtonType(GridButtonType.Image).ImageHtmlAttributes(new { style = "margin-left:0" }))
    .Columns(columns =>
        {
            columns.Bound(e => e.Category);
            columns.Bound(e => e.CompanyName);
            columns.Bound(e => e.Name);
            columns.Bound(e => e.TelephoneNumber);
            columns.Bound(e => e.MobileNumber);
            columns.Bound(e => e.Email);
            columns.Bound(e => e.BirthDate).Format("{0:dd-MM-yyyy}");
            columns.Command(commands =>
            {
                commands.Edit().ButtonType(GridButtonType.Image);
                commands.Delete().ButtonType(GridButtonType.Image);
            });
        })
    .DetailView(details => details.ClientTemplate(
        Html.Telerik().TabStrip()
            .Name("Tabstrip_<#= ContactId #>")
            .SelectedIndex(0)
            .Items(items =>
            {
                items.Add().Text("Detail Informatie")
                    .Content("<div class='employee-details'>" +
                             "<ul>" +
                             "<li><label>Soort Contact</label><#= Category #></li>" +
                             "<li><label>Bedrijsnaam</label><#= CompanyName #></li>" +
                             "<li><label>Naam</label><#= Name #></li>" +
                             "<li><label>Telefoonnummer</label><#= TelephoneNumber #></li>" +
                             "<li><label>Mobiel nummer</label><#= MobileNumber #></li>" +
                             "<li><label>Emailadres</label><#= Email #></li>" +
                             "<li><label>WebSite</label><a href='http://<;#= Website #>' target='_blank'><#= Website #></a></li>" +
                             "<li><label>Geboortedag</label><#= $.telerik.formatString('{0:dd-MM-yyyy}', BirthDate)#></li>" + 
                             "</ul>" + 
                             "</div>");
                items.Add().Text("Adressen").Content(
                    Html.Telerik().Grid<AddressModel>()
                    .Name("Adresses_<#= ContactId #>")
                    .Columns(columns =>
                        {
                            columns.Bound(o => o.AddressName);
                            columns.Bound(o => o.Street);
                            columns.Bound(o => o.PostalCode);
                            columns.Bound(o => o.Town);
                        })
                    .DataBinding(dataBinding => dataBinding.Ajax()
                        .Select("_AddressesForContact", "Contact", new { id = "<#= ContactId #>" }))
                    .Pageable()
                    .Sortable()
                    .Filterable()
                    .ToHtmlString());
                items.Add().Text("Notities").Content(
                    Html.Telerik().Grid<NoteModel>()
                    .Name("Notes_<#= ContactId #>")
                    .Localizable("nl-NL")
                    .DataKeys(keys => { keys.Add(c => c.NoteId); })
                    .ToolBar(commands => commands.Insert().ButtonType(GridButtonType.Image))
                    .Columns(columns =>
                    {
                        columns.Bound(o => o.TimeStamp).ReadOnly();
                        columns.Bound(o => o.Note);
                        columns.Command(commands =>
                        {
                            commands.Edit().ButtonType(GridButtonType.Image);
                            commands.Delete().ButtonType(GridButtonType.Image);
                        });
                    })
                    .DataBinding(dataBinding => dataBinding.Ajax()
                        .Select("_NotesForContact", "Contact", new { id = "<#= ContactId #>" })
                        .Insert("_InsertNoteForContact", "Contact", new { id = "<#= ContactId #>" })
                        .Update("_UpdateNoteForContact", "Contact", new { id = "<#= NoteId #>", contactId = "<#= ContactId #>" })
                        .Delete("_DeleteNoteForContact", "Contact", new { id = "<#= NoteId #>", contactId = "<#= ContactId #>" }))
                    .Sortable()
                    .Filterable()
                    .ToHtmlString());
                items.Add().Text("Emails").Content(
                    Html.Telerik().Grid<EmailMessageModel>()
                    .Name("Emails_<#= ContactId #>")
                    .Columns(columns =>
                    {
                        columns.Bound(o => o.TimeStamp);
                        columns.Bound(o => o.Message);
                    })
                    .DataBinding(dataBinding => dataBinding.Ajax()
                        .Select("_EmailsForContact", "Contact", new { id = "<#= ContactId #>" }))
                    .Sortable()
                    .Filterable()
                    .ToHtmlString());
            })
            .ToHtmlString()
    ))
    .DataBinding(dataBinding =>
    {        
        dataBinding.Ajax()
            .Select("_AllContacts", "Contact")
            .Insert("_InsertContact", "Contact")
            .Update("_SaveContact", "Contact")                
            .Delete("_DeleteContact", "Contact"); 
    })
    .Editable(editing => editing.Mode(GridEditMode.PopUp))
    .Sortable()    
    .Filterable()
)

the parent ("Contacts") edit works perfect, but in the child ("Notities") grid i'm not able to get the id ("NoteId") of the parent grid.
i need this to save the child row.

both id's are in the model.
Is it possible to get the id of the parent grid?

thanks in advance for reply.

btw, this mvc suite really rocks!

1 Answer, 1 is accepted

Sort by
0
Derk-Jan Sevink
Top achievements
Rank 1
answered on 12 Apr 2011, 07:22 PM
just saw an error in my post.
i'm able to get the id (contactid) of the parent grid.
i'm not able to get the id (noteid) of the child grid.

is what i'm trying to do possible?
is it going wrong because of the .ToHtmlString()?

help is greatly appreciated!
Tags
Grid
Asked by
Derk-Jan Sevink
Top achievements
Rank 1
Answers by
Derk-Jan Sevink
Top achievements
Rank 1
Share this question
or