Grid Column Grouping of ClientTemplate Text

2 posts, 0 answers
  1. Megan
    Megan avatar
    1 posts
    Member since:
    Sep 2020

    Posted 15 Sep 2020 Link to this post

       Hello, I have a grid that uses ClientTemplates to display the name associated with an id. When grouping, the id shows instead of the specified name. Is there any way to fix this to group by the selected text from the dropdown created in the ClientTemplate rather than the associated id?

     

    Grid

    @(Html.Kendo().Grid<BCGS.Classes.BCGSSite>
        ()
        .Name("sites")
        .Columns(columns =>
        {
            columns.Bound(s => s.SiteName).HeaderHtmlAttributes(new { @style = "font-weight:bold" }); ;
            columns.Bound(s => s.DistrictDisplayName).Title("District").HeaderHtmlAttributes(new { @style = "font-weight:bold" });
            columns.Bound(s => s.CountyId).Title("County").ClientTemplate("#=CountyName#").HeaderHtmlAttributes(new { @style = "font-weight:bold" });
            columns.Bound(s => s.Active).ClientTemplate("#= Active? 'Yes' : 'No' # <value ='#= Active #' />").HeaderHtmlAttributes(new { @style = "font-weight:bold" });
            columns.Bound(s => s.SiteCategoryId).Title("Category").ClientTemplate("#=CategoryName#").HeaderHtmlAttributes(new { @style = "font-weight:bold" });
            columns.Bound(s => s.SpecialtyId).Title("Speciality").ClientTemplate("#=SpecialtyName#").HeaderHtmlAttributes(new { @style = "font-weight:bold" });
            columns.Bound(s => s.Address1).Title("Address 1").HeaderHtmlAttributes(new { @style = "font-weight:bold" });
            columns.Bound(s => s.Address2).Title("Address 2").HeaderHtmlAttributes(new { @style = "font-weight:bold" });
            columns.Bound(s => s.City).HeaderHtmlAttributes(new { @style = "font-weight:bold" });
            columns.Bound(s => s.State).HeaderHtmlAttributes(new { @style = "font-weight:bold" });
            columns.Bound(s => s.PostalCode).Title("Zip Code").HeaderHtmlAttributes(new { @style = "font-weight:bold" });
            columns.Command(command => { command.Edit(); command.Destroy(); }).Width(240);
        })

        .Groupable(g => g.Enabled(true))
        .ToolBar(toolbar =>
        {
            toolbar.Search();
            toolbar.Excel();
            toolbar.Create();
        })
        .Excel(excel =>
        excel.FileName("Sites.xlsx")
        .ProxyURL(Url.Action("Excel_Export_Save", "Grid"))
        .AllPages(true))
        .Sortable()
        .Pageable()
        .Editable(editable => editable.Mode(GridEditMode.InLine))
        .DataSource(source => source
        .Ajax()
        .PageSize(50)
        .Events(events => {
            events.Error("error_handler");
            events.Sync("update");
        })
        .Model(model =>
        {
            model.Id(s => s.SiteID);
            model.Field(s => s.SiteName).Editable(true);
            model.Field(s => s.DistrictDisplayName).Editable(false);
            model.Field(s => s.SiteCategoryId).Editable(true);
            model.Field(s => s.CountyId).Editable(true);
            model.Field(s => s.Active).Editable(true).DefaultValue(true);
            model.Field(s => s.Address1).Editable(true);
            model.Field(s => s.Address2).Editable(true);
            model.Field(s => s.City).Editable(true);
            model.Field(s => s.State).Editable(true);
            model.Field(s => s.PostalCode).Editable(true);
            model.Field(s => s.SpecialtyId).Editable(true);
        })
        .Create(create => create.Action("SiteEdit", "Admin"))
        .Update(update => update.Action("SiteEdit", "Admin"))
        .Destroy(destroy => destroy.Action("SiteDelete", "Admin"))
        .Read(read => read.Action("SiteGrid", "Admin"))
        )
        )

     

    EditorTemplate

    @model BCGS.Classes.BCGSSite

    @(Html.Kendo().DropDownListFor(m => m)
                        .DataTextField("CountyName")
                        .DataValueField("CountyId")                  
                        .AutoBind(false)
                        .HtmlAttributes(new { data_value_primitive = "true"})
                        .OptionLabel(" ")
                        .BindTo((System.Collections.IEnumerable)ViewData["counties"]))

     

    Thank you,

    Megan

  2. Neli
    Admin
    Neli avatar
    397 posts

    Posted 18 Sep 2020 Link to this post

    Hi Megan,

    When grouping by a column, the grouping will be applied depending on the values for the given column. In case you need to group by a CountryName, you will need to have such a column configured.

    However, I would suggest you take a look at the article for Group Templates where it is described the way the group rows could be customized:

    - https://docs.telerik.com/kendo-ui/controls/data-management/grid/Templates/group-templates

    I hope this helps.

    Regards,
    Neli
    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/.

Back to Top