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

Get ID of current task using CustomEditorTemplate

1 Answer 173 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Gora
Top achievements
Rank 1
Gora asked on 17 Aug 2016, 08:00 AM

Hi i have an task scheduller

And would like to get ID of current task using  CustomEditorTemplate 

@Model.TaskID is always equals to 0

.Editable(editable =>
                  {
                      editable.TemplateName("CustomEditorTemplate");
                  })

 @(Html.Kendo().Scheduler<TaskViewModel>()
                  .Name("schedule")
                  .Date(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day))
                  .StartTime(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 9, 00, 00))
                  .EndTime(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 18, 00, 00))
                  .HtmlAttributes(new {@class = "ra-section"})
                 
                  .Views(views =>
                  {
                      views.DayView(dayView => dayView.Selected(true));
                      views.WeekView();
                      views.MonthView();
                      views.AgendaView();
                  })
                  .Editable(editable =>
                  {
                      editable.TemplateName("CustomEditorTemplate");
                  })
                  .Timezone("Etc/UTC")

                  .DataSource(dataSource => dataSource
                      .Model(m =>
                      {
                          m.Id(f => f.TaskID);
                          m.Field(f => f.Title);
                          m.Field(f => f.Start);
                          m.Field(f => f.End);
                          m.Field(f => f.Description);
                          m.Field(f => f.RecurrenceID);
                          m.Field(f => f.RecurrenceRule);
                          m.Field(f => f.RecurrenceException);
                          m.Field(f => f.IsAllDay);
                          m.Field(f => f.StartTimezone);
                          m.Field(f => f.EndTimezone);
                      })
                      .Events(e => e.Error("error_handler"))
                      .Read("ChargerTous", "TaskScheduler")
                      .Create("Ajouter", "TaskScheduler")
                      .Update("Modifier", "TaskScheduler")
                      .Destroy("Supprimer", "TaskScheduler")
                  )
                  )

And I have a custom editor template

@model Gloe.Web.Website.ViewModel.TaskViewModel
@{
    ViewContext.FormContext = new FormContext();
}

<div data-container-for="grid" class="k-edit-field">

        @(Html.Kendo().Grid<Gloe.Web.Website.ViewModel.TaskScheduler.PrelevementViewModel>()
    .Name("grid")
    .Columns(columns =>
    {

        columns.Bound(p => p.NomPrelevement).ClientTemplate("\\#= productDetails(data) \\#")
          .ClientFooterTemplate("count : \\#=count \\#")
            .ClientGroupFooterTemplate("count : \\#=count \\# ");
        columns.Bound(p => p.ValeurPrelevement).Width(120)
        .ClientFooterTemplate("Sum: \\#=sum\\# ")
            .ClientGroupFooterTemplate("Sum: \\#=sum\\# ");

        columns.Command(command => { command.Edit(); command.Destroy(); }).Width(250);

    })

    .ToolBar(toolbar => toolbar.Create())
    .Editable(editable => editable.Mode(GridEditMode.InLine))
    .Events(events => events.Change("onChange").DataBound("onDataBound").DataBinding("onDataBinding"))

    .DataSource(dataSource => dataSource
        .Ajax()
         .Aggregates(aggregates =>
         {
             aggregates.Add(p => p.NomPrelevement).Count();
             aggregates.Add(p => p.ValeurPrelevement).Sum();
         })
        .PageSize(20)

        .Model(model =>
        {
            model.Id(l => l.IdPrelevement);
            model.Field(field => field.IdPrelevement).Editable(false);
            model.Field(field => field.NomPrelevement).Editable(false);
            model.Field(field => field.ValeurPrelevement);
        })
        .Create(update => update.Action("EditingInline_Create", "RapportAnalyse").Data("additionalInfo"))
        .Read(read => read.Action("EditingInline_Read", "RapportAnalyse").Data("GetTaskID"))
        .Update(update => update.Action("EditingInline_Update", "RapportAnalyse"))
        .Destroy(update => update.Action("EditingInline_Destroy", "RapportAnalyse"))
    )
        )
    </div>
</div>

@{
    ViewContext.FormContext = null;
}

1 Answer, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 18 Aug 2016, 10:10 AM
Hello Gora,

Current behavior is expected as the editor template is initialized on the server side with empty instance of the model type. Later on the client side the currently edited event is bind to the template HTML / JavaScript output using MVVM

There are several ways to achieve the desired behavior and which one you would choose depends entirely on you and the exact setup that you have. For example you can use the "Edit" event of the Scheduler to set the Grid dataSource ("setDataSource" method). Another option is to nest hidden input inside the editor which to be bind to the ID field and get it's value inside the Grid DataSource (example here). 

Regards,
Vladimir Iliev
Telerik by Progress
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 Feedback Portal and vote to affect the priority of the items
Tags
Scheduler
Asked by
Gora
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Share this question
or