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

[Solved] Master/Detail - Detail Not Showing

15 Answers 286 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.
Michael
Top achievements
Rank 1
Michael asked on 16 Feb 2011, 12:11 PM
Hello,

i'm trying to show the master/detail, and the detail won't show until I click Edit on the master row and save.  So, initially when the grid appears, the + signs appear but when I click on them, no data displayed.  The data is displayed after I click on Edit on the master line and save. 

Here is my view:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<GridAlphabeticPaging.Models.AlphabeticStudentsViewModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
 Index
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <h2>Students</h2>

    <%Html.Telerik()
            .Grid(Model.Students)
            .Name("Students")
            .DataKeys(k => k.Add(s => s.StudentID))
            .DataBinding(dataBinding => dataBinding
                //Server binding
                .Ajax()
                    //Home.Index renders the grid initially
                    .Select("Index", "Student")
                    //Home.Insert inserts a new data record
                    .Insert("Insert", "Student")
                    //Home.Update updates an existing data record
                    .Update("Update", "Student")
                    //Home.Delete deletes an existing data record
                    .Delete("Delete", "Student")
            )
            .ToolBar(toolBar => toolBar.Template(() =>
            {%>
                <a href="#" class="t-grid-action t-button t-state-default t-grid-add">Add Student</a>
                <div class="t-pager-wrapper" style="border-bottom:0">
                    <div class="t-pager t-reset">                               
                        <%foreach (var letter in Model.Letters){%>
                            <%=Html.ActionLink(letter, "Index", new { letter }, new { @class = "t-link" })%>
                        <%}%>
                        <%=Html.ActionLink("All", "Index")%>                                                       
                    </div>
                </div>
            <%}))
            .Columns(columns =>
            {
                columns.Bound(s => s.FirstName).Width(20).Filterable(true);
                columns.Bound(s => s.LastName).Width(20).Filterable(true);
                columns.Bound(s => s.City).Width(20).Filterable(false);
                columns.Bound(s => s.State).Width(20).Filterable(false);
                columns.Bound(s => s.Cell).Width(20).Filterable(false);
                columns.Command(commands =>
                {
                    commands.Edit();
                    commands.Delete();
                    commands.Select();
                }).Width(100);
            })
            .DetailView(detailView => detailView.ClientTemplate(
                // Define a grid bound to the Order object
                Html.Telerik().Grid<Models.StudentSchool>()
                //Ensure the Name of each grid is unique
                     .Name("Schools_<#= StudentID #>")
                     .DataBinding(dataBinding => dataBinding.Ajax()
                         // Specify the action method which returns the Orders for a particular Employee
                         // Notice how the `EmployeeID` value is passed as the `id` argument using a client expression
                     .Select("Schools", "Student", new { id = "<#= StudentID #>" }))
                     .Columns(columns =>
                     {
                         columns.Bound(c => c.StudentID);
                         columns.Bound(c => c.SchoolID);
                     })
                     .Pageable()
                // The client detail view template requires a string so we are using the ToHtmlString method
                     .ToHtmlString()
            ))
          // Handle the OnRowDataBound event in order to expand certain rows
            .ClientEvents(events => events.OnRowDataBound("onRowDataBound"))                                                                                                                                    
            .Filterable(filtarable => filtarable.Filters(filters =>
            {
                if(!string.IsNullOrEmpty(Model.SelectedLetter))
                {
                    filters.Add(s => s.LastName).StartsWith(Model.SelectedLetter);
                }
            }))
            .Scrollable(c => c.Height("400px"))
            .HtmlAttributes(new { @style = "width:100%" })
            .Selectable()
            .Editable(editing => editing.Mode(GridEditMode.PopUp))
            .Render();
    %>
   
<script type="text/javascript">
    function onRowDataBound(e) {
        var grid = $(this).data('tGrid');
        // Expand the first row only
        if (grid.$rows().index(e.row) == 0) {
            grid.expandRow(e.row);
        }
    }
</script>

</asp:Content>

 


15 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 16 Feb 2011, 12:28 PM
Hi Michael,

 This is very strange because  your code looks perfectly ok. Do you see any JavaScript errors? A JavaScript error may prevent the detail view from working. Is there a chance to send us a project which reproduces the problem?

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
H
Top achievements
Rank 1
answered on 16 Feb 2011, 06:04 PM
We're having a related problem with the +/- on the Master/Detail views.

This just started with an upgrade to the 2010.3.1318 release.

We have a grid with a Master -> Detail -> Detail hierarchy, Server binding.  When the 1st level of detail is expanded, it works fine.  But when you click on the + for the 2nd level of detail, nothing happens, the row is not expanded.  I tried putting in a RowAction to expand both levels on initial entry to the view, and that works fine & expands both levels, but then when you click on the - to collapse the 2nd level of detail, nothing happens.  Clicking the - to collapse the first level works fine.

The same grid is working in release 2010.2.1101.

If I look at the HTML using Developer Tools, I can see the data is there for that 2nd level of detail,  so it's something to do with the +/- not responding.  Any suggestions?
0
Michael
Top achievements
Rank 1
answered on 16 Feb 2011, 06:29 PM
The master row are Students, and the child row is schools.  I'm using linq to sql and I set the child property relationship between the two to false.  When I had it set to true I was getting different compile errors.  So then, when I set it to false, the grid rendered, but there were blank child rows, and the child row appears as mentioned when I update the master row.

This is my controller:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Company.Models;
using GridAlphabeticPaging.Models;
using Telerik.Web.Mvc;

namespace Company.Controllers
{
    public class StudentController : Controller
    {
        //
        // GET: /Student/

        IStudentRepository studentRepository;

        public StudentController() : this(new StudentRepository())
        {
        }

        public StudentController(IStudentRepository repository)
        {
            studentRepository = repository;
        }

        [GridAction]
        public ActionResult Index(string letter)
        {

            return View(new AlphabeticStudentsViewModel
            {
                Students = studentRepository.All(),
                //Students = db.Students,
                Letters = Enumerable.Range(65, 25).Select(i => ((char)i).ToString()),
                SelectedLetter = letter
            });

        }

        //
        // GET: /Student/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

 

        [HttpPost]
        [GridAction]
        //public ActionResult Insert([Bind(Exclude = "StudentID")]
        //                    Student student)
        public ActionResult Insert()
        {
            //Create a new instance of the EditableCustomer class.
            Student student = new Student();
           
            //Perform model binding (fill the customer properties and validate it).
            if (TryUpdateModel(student))
            {
                //The model is valid - insert the customer.
                studentRepository.Insert(student);
                studentRepository.Save();
            }

            //Rebind the grid
            return View(new GridModel(studentRepository.All()));
        }

       
        //
        // GET: /Student/Edit/5

        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Student/Edit/5

        [AcceptVerbs(HttpVerbs.Post)]
        [GridAction]
        public ActionResult Update(int id)
        {
            Student student = studentRepository.GetStudent(id);
            UpdateModel(student);
            studentRepository.Save();
            return View(new GridModel(studentRepository.All()));
        }

        [GridAction]
        public ActionResult Schools(int id)
        {

            return View(new GridModel(new CompanyDataContext().StudentSchools.Where(s => s.StudentID == id)));

        }

       
    }
}


0
Atanas Korchev
Telerik team
answered on 17 Feb 2011, 10:55 AM
Hi,

 Unfortunately we cannot provide any further help without reproducing the problem first. Please send us some runnable code with this regard. You can use dummy in-memory data to avoid sending us production databases. 

Looking forward to your reply!

Regards,
Atanas Korchev
the Telerik team
0
Michael
Top achievements
Rank 1
answered on 17 Feb 2011, 06:31 PM
Here you go.  On the Home view, click Employees and it will take you to the grid which has the problems I've mentioned.

Thank you.
0
Michael
Top achievements
Rank 1
answered on 17 Feb 2011, 10:59 PM
I think the error is happening because I need to return a GridModel in the code below.  How can I modify the code below to return the GridModel?

[

GridAction]

 

 

 

public ActionResult Index(string letter)

 

 

{

 

 

return View(new AlphabeticEmployeesViewModel

 

{

Employees = EmployeeRepository.All(),

Letters =

Enumerable.Range(65, 25).Select(i => ((char)i).ToString()),

 

 

SelectedLetter = letter

 

});

 

}



0
Atanas Korchev
Telerik team
answered on 18 Feb 2011, 08:19 AM
Hi Michael,

 The constructor of the GridModel needs an IEnumerable<T>. You can try this:

return View(new GridModel(EmployeeRepository.All()));

All the best,
Atanas Korchev
the Telerik team
0
Michael
Top achievements
Rank 1
answered on 18 Feb 2011, 11:51 AM
I tried that and it doesn't work because my view inherits from:

Inherits

 

="System.Web.Mvc.ViewPage<GridAlphabeticPaging.Models.AlphabeticEmployeesViewModel>"

 


Because I am using the alphbetic paging example you have online.  How am I suppose to return the Letters and SelectedLetter varaibles then?
0
Atanas Korchev
Telerik team
answered on 18 Feb 2011, 12:23 PM
Hello Michael,

 The ajax method which feeds the grid (decorated with the GridAction attribute) never renders the actual view.

Regards,
Atanas Korchev
the Telerik team
0
Michael
Top achievements
Rank 1
answered on 18 Feb 2011, 12:36 PM
I posted a runnable project, and if that is the only change I make, the project won't run. 

I guess I'm just unsure what else I need to change at this point.

Thanks.
0
Atanas Korchev
Telerik team
answered on 18 Feb 2011, 01:24 PM
Hi Michael, 

I somehow missed your attachment. Now after reviewing it I know what the problem is.

 Originally the alphabetic pager example is using server binding. In your project you are defining the client detail template which is however populated only if you are using client binding for the master grid. This is  the reason why the child template is empty initially and appears after editing a record. There are two possible ways to solve this problem:

  1. Convert the alphabetic paging to work with ajax bound master grid
  2. Use only server binding (thus server detail template) for the child and master grids

I implemented the first option and I am attaching the updated project.

Regards,
Atanas Korchev
the Telerik team
0
Michael
Top achievements
Rank 1
answered on 18 Feb 2011, 01:27 PM
Thank you! I'm downloading this project now!

Thanks again for the timely response!

Michael
0
Michael
Top achievements
Rank 1
answered on 18 Feb 2011, 02:10 PM
Atanas,

When I click on the Add button in the toolbar, the insert popup is displayed and immediately disappears.  Do you know why?

Thanks...
0
Atanas Korchev
Telerik team
answered on 18 Feb 2011, 02:13 PM
Hello Michael,

 Probably because of the code in onLoad which performs the alphabetic paging. Change the selector to exclude the add link:

$(this).find("> .t-grid-toolbar a:not(.t-grid-add)").click(function(e) {

Regards,
Atanas Korchev
the Telerik team
0
Michael
Top achievements
Rank 1
answered on 18 Feb 2011, 02:29 PM
Thanks again for all your help.
Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
H
Top achievements
Rank 1
Michael
Top achievements
Rank 1
Share this question
or