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

[Solved] Get parent row of grid

2 Answers 161 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 15 Apr 2012, 09:19 PM
I have a custom editortemplate that I need to pass a value to in order to have conditional display logic.
My master grid has a field called Unlimited.  I need to pass the value to the editortemplate and then have a if condition based on that value when a detailview child edit or insert is executed.


On the onedit of my detail view I have the on edit event:
.ClientEvents(events => events.OnEdit("onEditSlots"))

    function onEditSlots(e) {
        var dataItem = e.dataItem;
        var mode = e.mode;
        var form = e.form;
        var txt = $(form).find("#UnlimitedSlots");

        var masterRow = $(e.form).closest('.t-detail-row').prev();
        var parentDataItem = masterRow.closest('.t-grid').data('tGrid').dataItem(masterRow);

        if (mode == "insert") {
            txt.val(parentDataItem["UnlimitedSlots"]);
        }

        if (mode == "edit") {
            txt.val(dataItem["UnlimitedSlots"]);
        }
    }


But the line that reads:
var parentDataItem = masterRow.closest('.t-grid').data('tGrid').dataItem(masterRow);

gives me an error saying dataItem is null.

In my editortemplate, I want an if condition if unlimitedslots = true else if unlimitedslots = false execute something else.
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MVCProject.ViewModels.SlotViewModel>" %>
<%= Html.TextBox("UnlimitedSlots").value.Equals(true) ? "Slots: Unlimited" : "Slots:" + Html.TextBoxFor(x => x.Slots) %>

my grid detail view that is displayed in a tab:
                    items.Add().Text("Slots").Content(
                          Html.Telerik().Grid<MVCProject.ViewModels.SlotViewModel>()
                              .Name("Slots_<#= \ID #>")
                              .ToolBar(commands => commands.Insert())
                              .DataKeys(keys => keys.Add(f => f.SlotID))
                              .ClientEvents(events => events.OnEdit("onEditSlots"))
                              //ommitted for brevity
                           .ToHtmlString());

2 Answers, 1 is accepted

Sort by
0
MICHAEL
Top achievements
Rank 1
answered on 16 Apr 2012, 10:43 AM
If I didn't explain this correctly, my main goal is passing a parameter used by a master row to a custom editortemplate for a child row that I can use in an if condition in the editortemplate. This needs to be used on a insert or edit.

If someone can please provide an example, that would be great.


0
MICHAEL
Top achievements
Rank 1
answered on 16 Apr 2012, 10:38 PM
Anyone have any idea? Any help would be greatly appreciated.
Tags
Grid
Asked by
MICHAEL
Top achievements
Rank 1
Answers by
MICHAEL
Top achievements
Rank 1
Share this question
or