All Components

PivotGrid / Templates

HTML5/JavaScript 源码

<!DOCTYPE html>
<html>
 <head> 
  <title>Templates</title> 
  <meta charset="utf-8"> 
  <link href="../content/shared/styles/examples-offline.css" rel="stylesheet"> 
  <link href="../../styles/kendo.common.min.css" rel="stylesheet"> 
  <link href="../../styles/kendo.rtl.min.css" rel="stylesheet"> 
  <link href="../../styles/kendo.default.min.css" rel="stylesheet"> 
  <link href="../../styles/kendo.dataviz.min.css" rel="stylesheet"> 
  <link href="../../styles/kendo.dataviz.default.min.css" rel="stylesheet"> 
  <script src="../../js/jquery.min.js"></script> 
  <script src="../../js/kendo.all.min.js"></script> 
  <script src="../content/shared/js/console.js"></script> 
  <script>
        
    </script> 
 </head> 
 <body> 
  <a class="offline-button" href="../index.html">Back</a> 
  <div id="example"> 
   <div id="pivotgrid" class="hidden-on-narrow"></div> 
   <div class="responsive-message"></div> 
   <script id="dataCellTemplate" type="text/x-kendo-tmpl">
                # var columnMember = columnTuple ? columnTuple.members[0] : { children: [] }; #
                # var rowMember = rowTuple ? rowTuple.members[0] : { children: [] }; #
                # var value = kendo.toString(kendo.parseFloat(dataItem.value) || "N/A", "c2"); #

                # if (columnMember.children.length || rowMember.children.length) { #
                    <em  style="color: red">#: value # (total)</em>
                # } else { #
                    #: value #
                # } #
            </script> 
   <script id="headerTemplate" type="text/x-kendo-tmpl">
                # if (!member.children.length) { #
                    <em>#: member.caption #</em>
                # } else { #
                    #: member.caption #
                # } #
            </script> 
   <script>
                $(document).ready(function () {
                    $("#pivotgrid").kendoPivotGrid({
                        dataCellTemplate: $("#dataCellTemplate").html(),
                        columnHeaderTemplate: $("#headerTemplate").html(),
                        rowHeaderTemplate: $("#headerTemplate").html(),
                        columnWidth: 200,
                        height: 320,
                        dataSource: {
                            type: "xmla",
                            columns: [{ name: "[Date].[Calendar]", expand: true }],
                            rows: [{ name: "[Product].[Product Line]", expand: true }],
                            measures: ["[Measures].[Reseller Freight Cost]"],
                            transport: {
                                connection: {
                                    catalog: "Adventure Works DW 2008R2",
                                    cube: "Adventure Works"
                                },
                                read: "//demos.telerik.com/olap/msmdpump.dll"
                            },
                            schema: {
                                type: "xmla"
                            },
                            error: function (e) {
                                alert("error: " + kendo.stringify(e.errors[0]));
                            }
                        }
                    });
                });
            </script> 
  </div>   
 </body>
</html>