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

Cannot add rows when I have a group header

6 Answers 24 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.
SEAN
Top achievements
Rank 1
SEAN asked on 08 Oct 2011, 07:42 PM
If I use ClientGroupHeaderTemplate with a group in the grid with Ajax binding and InCell editing then adding rows no longer works. When I click the Add button the new row is not visible at the top of the grid as usual.

6 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 10 Oct 2011, 09:36 AM
Hello Sean,

Could you please download the Q2 2011 SP1 release and see if there is a change in the described behavior. 

Regards,
Rosen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
SEAN
Top achievements
Rank 1
answered on 10 Oct 2011, 01:34 PM
Hi Rosen,

That does not fix it. I'm seeing this error in the Javascript

Cannot read property 'Name' of null

Name is my grouping column. This only happens when I have a ClientGroupHeaderTemplate, if I remove that then the insert works fine with the grouping.

Sean
0
Rosen
Telerik team
answered on 10 Oct 2011, 04:26 PM
Hi Sean,

Could you please provide (using the Format Code button) the grid's declaration?

All the best,
Rosen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
SEAN
Top achievements
Rank 1
answered on 11 Oct 2011, 12:48 AM
This is the code that gives the error when I try to insert a row:
@(Html.Telerik().Grid<Sean.Projects.ViewModels.GroupedReqEntry>()
        .Name("ReqsGrid")
        .ToolBar(commands =>
        {
            commands.Insert();
            commands.SubmitChanges();
        })
        .DataKeys(keys =>
        {
            keys.Add(r => r.Id);
        })
        .Columns(columns =>
        {
            columns.Bound(r => r.Name)
                .Title("Req Name")
                .Width(200);
            columns.Bound(r => r.Description).Title("Description").Encoded(false);
            columns.Command(commands => { commands.Delete().ButtonType(GridButtonType.Image); }).Width(40);
            columns.Bound(r => r.ReqGroup.Name)
                .Hidden(true)
                .Aggregate(aggregates => aggregates.Count())
                .ClientGroupHeaderTemplate("Group: <#= Key #> (<#= Count #> reqs)");
        })
        .DataBinding(dataBinding =>
        {
            dataBinding.Ajax()
                .Select("_AjaxGroupedBinding", "Reqs")
                .Update("_AjaxGroupedBatchUpdate", "Reqs");
        })
        .Editable(editing => editing.Mode(GridEditMode.InCell))
        .Scrollable(s => s.Height(500))
        .Sortable(sorting => sorting
            .OrderBy(sortOrder => sortOrder.Add(r => r.Name)))
        .Resizable(c => c.Columns(true))
        .Reorderable(c => c.Columns(true))
        .Groupable(grouping => grouping.Groups(groups =>
        {
            groups.Add(r => r.ReqGroup.Name);
        })
            .Visible(false)
        )
        .KeyboardNavigation()
        .NoRecordsTemplate("No reqs found for this project.")
        .ClientEvents(events =>
        {
            events.OnSubmitChanges("onSubmitChanges");
            events.OnDataBinding("onDataBinding");
            events.OnEdit("onEdit");
            events.OnSave("onSave");
            events.OnLoad("onLoad");
            events.OnDataBound("onDataBound");
            events.OnRowSelect("onRowSelect");
        })
    )


This works fine for inserting a row, but now I don't have my count in the group header:
@(Html.Telerik().Grid<Sean.Projects.ViewModels.GroupedReqEntry>()
        .Name("ReqsGrid")
        .ToolBar(commands =>
        {
            commands.Insert();
            commands.SubmitChanges();
        })
        .DataKeys(keys =>
        {
            keys.Add(r => r.Id);
        })
        .Columns(columns =>
        {
            columns.Bound(r => r.Name)
                .Title("Req Name")
                .Width(200);
            columns.Bound(r => r.Description).Title("Description").Encoded(false);
            columns.Command(commands => { commands.Delete().ButtonType(GridButtonType.Image); }).Width(40);
        })
        .DataBinding(dataBinding =>
        {
            dataBinding.Ajax()
                .Select("_AjaxGroupedBinding", "Reqs")
                .Update("_AjaxGroupedBatchUpdate", "Reqs");
        })
        .Editable(editing => editing.Mode(GridEditMode.InCell))
        .Scrollable(s => s.Height(500))
        .Sortable(sorting => sorting
            .OrderBy(sortOrder => sortOrder.Add(r => r.Name)))
        .Resizable(c => c.Columns(true))
        .Reorderable(c => c.Columns(true))
        .Groupable(grouping => grouping.Groups(groups =>
        {
            groups.Add(r => r.ReqGroup.Name);
        })
            .Visible(false)
        )
        .KeyboardNavigation()
        .NoRecordsTemplate("No reqs found for this project.")
        .ClientEvents(events =>
        {
            events.OnSubmitChanges("onSubmitChanges");
            events.OnDataBinding("onDataBinding");
            events.OnEdit("onEdit");
            events.OnSave("onSave");
            events.OnLoad("onLoad");
            events.OnDataBound("onDataBound");
            events.OnRowSelect("onRowSelect");
        })
    )


Sean
0
Rosen
Telerik team
answered on 11 Oct 2011, 08:13 AM
Hi Sean,

Although, not able to recreate this issue locally, I suspect that it may be caused by the grouping on complex object property, which when created during insertion will lack the nested object instance.  Therefore, you may use the DefaultDataItem option to set a valid default instance of the inserted object.
If you continue to experiencing difficulties please provide a small sample in which this issue can be observed locally.

Regards,
Rosen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
SEAN
Top achievements
Rank 1
answered on 12 Oct 2011, 01:26 AM
That was it, thanks Rosen

I don't really have a default value but I can put a fake object in their and then it doesn't fail.

Sean
Tags
Grid
Asked by
SEAN
Top achievements
Rank 1
Answers by
Rosen
Telerik team
SEAN
Top achievements
Rank 1
Share this question
or