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

groupHeaderTemplate, field not in columns

2 Answers 351 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Christoph
Top achievements
Rank 1
Christoph asked on 27 Feb 2013, 04:14 PM
Hi!

I just do my first steps with KendoUI and came across a problem I see no sultion for:
I bind a dataSource to a grid. The dataSource is grouped by a field which is not used in the grid:


    var dsCountries = new kendo.data.DataSource({
    type: "json",
    transport: {
        read: {
            url: '@Url.Action("GetCountries", "Home")',
            dataType: "json",
            type: "POST"
    }},
    schema: {
        data: "data",
        total: "total",
        model: {
            id: 'CountryID',
            fields: {
                Country: { type: "string" },
                Currency: { type: "string" },
                Size: { type: "double" },
                Continent: { type: "string" }
    }}},
    group: {
        field: "Continent", aggregates: [
            { field: "Size", aggregate: "sum" }
        ]
    },
    aggregate: [ { field: "Size", aggregate: "sum" } ],
    sort: { field: "Country", dir: "asc" },
    pageSize: 100,
    serverPaging: true,
    serverFiltering: true,
    serverSorting: true
});
 
var detailGrid = $("<div id=\"grid\" />").kendoGrid({
    dataSource: dsCountries,
    groupable: false,
    sortable: false,
    pageable: false,
    scrollable: false,
    columns: [
        { field: "Country", width: 200, title: "Text" },
        { field: "Currency", width: 200, title: "Text" },
        {
            field: "Size", width: 70, title: "Size", format: "{0:n}", attributes: { "Class": "numbers" },
            groupFooterTemplate: "<div class=\"numbers\">#=kendo.toString(sum, 'n') #</div>",
            footerTemplate: "<div class=\"numbers\">#=kendo.toString(sum, 'n') #</div>"
    }
    ]
});
Everything's OK so far, but now I want to define a groupHeaderTemplate für the 'Continent'-Field; the way it is displayed now in the GroupHeader, which is something like [Fieldname]: [Fieldvalue]. Right now, only displaying [Fieldvalue] would be good enough, but the best solution would offer a complete template.
Can this be done (easily)?

Another thing quite similiar: When the (nondisplayed) grouping field is boolean ('true' and 'false' ist displayed): Is the a way to display alternate values like 
groupingboolean ? "Yes" : "No";
Thanks in advance

2 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 01 Mar 2013, 11:07 AM
Hello Christoph,

A groupHeaderTemplate cannt be used without defining the column. In order to specify the template but do not show the column, I can suggest to use a hidden column e.g.

columns: [
    {field: "Continent", hidden: true, groupHeaderTemplate: myTemplate},
Regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Christoph
Top achievements
Rank 1
answered on 04 Mar 2013, 08:16 AM
Daniel,

thanks for your reply. It works perfectly.
And I got a Solution for my 2nd issue by Using a Template:

<script type="text/x-kendo-tmpl" id="rrHeaderTemplate">
    #if (value == false) { #
    Don't
    # } #
    use it!
</script>
Regards,
Chris
Tags
Grid
Asked by
Christoph
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Christoph
Top achievements
Rank 1
Share this question
or