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

Passing additional value to popup

5 Answers 1864 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Attila
Top achievements
Rank 2
Attila asked on 29 Sep 2017, 06:29 PM

Hi! 

Is it possible to pass additional data from my grid to the popup window beside the bound object?

@(Html.Kendo().Grid<GazoraAllasModels>()
          .Name("grid")
          .Columns(columns =>
          {
              columns.Bound(c => c.Oraallas).Title("Óraállás");
              columns.Bound(c => c.LeolvasasDatum).Title("Leolvasás dátuma");
          })
          .Editable(e => e.Mode(GridEditMode.PopUp).TemplateName("AddOraallas").AdditionalViewData(new { maxOra = "=#MaxOra()#" }))

 

I would like to pass data of a return value of javascript function as you can see (MaxOra()

On the editable template cshtml file has @ViewData["maxOra"] but the value is the string of "=#MaxOra#" and not the value. The cshtml starts with these lines, so I cannot pass this value in model:

@model MyProject.Models.MyProjectModels
@using Kendo.Mvc.UI
@ViewData["maxOra"]

This value cannot be in the model class. I really need to pass it as additional data.

Thanks

5 Answers, 1 is accepted

Sort by
0
Accepted
Stefan
Telerik team
answered on 03 Oct 2017, 10:10 AM
Hello, Attila,

Currently, the additional data can be passed only as static data.

@{
    string customValue= "some value";
}
 
.AdditionalViewData(new {customValue= customValue})

The other option will be to use the document ready event of the Custom template used for editing to execute a function which will be called every time the template is used:

<script>
    $(document).ready(function () {
        var uid = $("#@ChildGridName").closest("[data-uid]").data("uid");
        var parentGrid = $("#@ViewData["GridName"]").data("kendoGrid");
        var model = parentGrid.dataSource.getByUid(uid);
        console.log(model)
    });
</script>

I hope this is helpful.

Regards,
Stefan
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
ziental
Top achievements
Rank 1
answered on 11 Sep 2018, 01:36 PM

Hi Stefan,

I have the same problem but I can not solve it by your example.

I need to get the ID of the record being used in the Edit Template.
In this Template I'm using @Html.HiddenFor(b => b.UserID) but I also could not get the value for it.

See part of my code:

 @(Html.Kendo().Grid<Site.Models.BullViewModel>()
    .Name("grid")
.Editable(editable => editable.Mode(GridEditMode.PopUp)
        .DisplayDeleteConfirmation(false)
        .TemplateName("BullEdit").Window(w => w.Title("Bull")))

0
Stefan
Telerik team
answered on 12 Sep 2018, 02:16 PM
Hello, Zdzislaw,

The UserID value should be available directly inside the template.

Please refer to the following project demonstrating how to set up the editors inside the template when a custom popup editor is used inside the Grid:

https://github.com/telerik/ui-for-aspnet-mvc-examples/tree/master/grid/custom-popup-editor

If the issue still occurs please provide an example reproducing it as this will allow providing a suggestion best suited for it.

Regards,
Stefan
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
ziental
Top achievements
Rank 1
answered on 12 Sep 2018, 05:44 PM

Hi Stefan,

 

I'll try to explain the situation in more detail.

I have a grid that is a list of bulls, when the bull is clicked, a popup with the bull data opens.

So far so good, bull data is being sent to "EditorTemplates" without any problems. All controls are populated with model data.

This popup has the control "Html.Kendo (). TabStrip ()", in tab 1 are all the data of the model, and in tab 2 it must be populated with data that is not in this model.

My idea is to populate these other data using jquery, and when the user is "saving" the changes I save these two types of data separately.
 The problem is that I am not able to "get" the UserID that is used in a hidden control, as shown below.
@Html.HiddenFor (b => b.UserID)

This object is created with the name "UserID";

But when I try to "catch" this value, it is always null.

Any suggestions on how to solve this situation or how to "read" the value of this control?

0
Konstantin Dikov
Telerik team
answered on 14 Sep 2018, 01:06 PM
Hello,

Could you please elaborate if the UserID is part of the Grid model, because if it is part from the edited dataItem, its value should be set to the hidden input element when the editor template is bound?

If the issue persists you could open support ticket and attach a runnable project demonstrating the scenario and the issue, so we can test and debug it locally.


Regards,
Konstantin Dikov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Attila
Top achievements
Rank 2
Answers by
Stefan
Telerik team
ziental
Top achievements
Rank 1
Konstantin Dikov
Telerik team
Share this question
or