Get ID of current task using CustomEditorTemplate

2 posts, 0 answers
  1. Gora
    Gora avatar
    5 posts
    Member since:
    Dec 2011

    Posted 17 Aug Link to this post

    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;
    }

  2. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2172 posts

    Posted 18 Aug Link to this post

    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
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top