How to pass column value of grid in EditorViewData("#=?#")

1 Answer 478 Views
Editor Grid
Prakash Kumar Nambi
Top achievements
Rank 1
Prakash Kumar Nambi asked on 27 Sep 2022, 01:32 PM

Grid :-

.Columns(columns =>
{
    columns.Bound(x => x.Role).Title("<b>Project OBS Role</b>").Width("30%").Filterable(true).
    HeaderHtmlAttributes(new { style="text-align:center;"}).HeaderHtmlAttributes(new { style = "text-align:center;vertical-align:middle;" });

    columns.Bound(x => x.UserId).Title("<b>Approver</b>").Width("40%").EditorTemplateName("GridGroupPeoplePicker").
   ====>  EditorViewData(new { SecurityGroup = "#=SecurityGroup#" }).Filterable(true).HeaderHtmlAttributes(new { style = "text-align:center;vertical-                     align:middle;"       }).HtmlAttributes(new { style = "text-align:left;" });

    columns.Bound(x => x.Delay).Title("<b>Delay<b>").Width("20%").Filterable(true).
    HeaderHtmlAttributes(new { style = "text-align:center;vertical-align:middle;" }).HtmlAttributes(new { style = "text-align:left;" });

    columns.Command(command => { command.Edit().Text(" ").CancelText(" ").UpdateText(" ");}).Width("10%").
    HtmlAttributes(new { style = "text-align:center;" });
})

 

Editor Template :-

@model string
@{
    string Groups = ViewData["SecurityGroup"] as string;
}
<input type="hidden" id="hdn@(Html.IdForModel())" data-bind="value: @(Html.IdForModel())" disabled="disabled" />
<input type="hidden" id="GroupName_@(Html.IdForModel())" data-bind="value: @(Groups)" disabled="disabled" />
<script>
    function GetGroups_@(Html.IdForModel())(e) {
        debugger;
        var filterInput = $('#hdn@(Html.IdForModel())').val();
        var Groups = $('#GroupName_@(Html.IdForModel())').val();
        return { PickerFilter: filterInput, GroupNames: '@Groups', IsUsersByGroup: 'false' };
    }
</script>
@(Html.Kendo().DropDownListFor(m => m)
        .DataValueField("Value")
        .DataTextField("Text")
        .Filter(FilterType.Contains)
        .MinLength(3)
        .AutoBind(false)
        .DataSource(ds =>
        {
            ds.ServerFiltering(true).Read(r => r.Action("GetUserByGroups", "Common").Data("GetGroups_" + Html.IdForModel()));
        })
)

1 Answer, 1 is accepted

Sort by
0
Aleksandar
Telerik team
answered on 30 Sep 2022, 08:26 AM

Hello,

I can suggest reviewing this forum thread where the same scenario has been discussed. In general, the editor templates used for the Grid initialization come from the server and are evaluated only once, at initialization and against an empty model - that is why when the EditorTemplate is generated the passed "SecurityGroup" will be null or the default value for the property. 

As suggested in the thread you can use a .Data handler to access the edited model and get the required additional data.

Regards,
Aleksandar
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Editor Grid
Asked by
Prakash Kumar Nambi
Top achievements
Rank 1
Answers by
Aleksandar
Telerik team
Share this question
or