Kendo UI for jQuery數據管理使用教程:PivotGrid - 顯示工具提示

Kendo UI for jQuery R1 2021 SP2試用版下載

Kendo UI是帶有jQuery、Angular、React和Vue庫的JavaScript UI組件的最終集合,無論選擇哪種JavaScript框架,都可以快速構建高性能響應式Web應用程序。通過可自定義的UI組件,Kendo UI可以創建數據豐富的桌面、平板和移動Web應用程序。通過響應式的佈局、強大的數據綁定、跨瀏覽器兼容性和即時使用的主題,Kendo UI將開發時間加快了50%。

以下示例演示了當用戶將鼠標懸停在Kendo UI PivotGrid小部件中的數據單元格元素時如何顯示工具提示。

<script src="https://demos.telerik.com/kendo-ui/content/shared/js/products.js"></script>
<div id="example">

<div id="pivotgrid"></div>

<script id="template" type="text/x-kendo-template">
<div>
<div>Rows: #:rowText#</div>
<div>Columns: #:columnText#</div>
<div>Value: #:value ? value : "N/A" #</div>
</div>
</script>

<script>
$(document).ready(function () {
$("#pivotgrid").kendoPivotGrid({
columnWidth: 120,
height: 570,
dataSource: {
data: products,
schema: {
model: {
fields: {
ProductName: { type: "string" },
UnitPrice: { type: "number" },
UnitsInStock: { type: "number" },
Discontinued: { type: "boolean" },
CategoryName: { field: "Category.CategoryName" }
}
},
cube: {
dimensions: {
ProductName: { caption: "All Products" },
CategoryName: { caption: "All Categories" },
Discontinued: { caption: "All Discontinued" }
},
measures: {
"Sum": { field: "UnitPrice", format: "{0:c}", aggregate: "sum" }
}
}
},
rows: [{ name: "CategoryName", expand: true }, { name: "ProductName" } ],
columns: [{ name: "Discontinued", expand: true }],
measures: ["Sum"]
}
});

$(".k-grid-content").kendoTooltip({
filter: "td",
content: toolTip,
width: 400,
height: 100,
position: "top"
});

$(".k-grid-content").click(toolTip);

function toolTip(e) {
var target = $(e.target);
var grid = $("#pivotgrid").getKendoPivotGrid();

var cellInfo = grid.cellInfoByElement(target);

return kendo.template($("#template").html())({
rowText: generateName(cellInfo.rowTuple),
columnText: generateName(cellInfo.columnTuple),
value: cellInfo.dataItem.fmtValue
});
}

function generateName(tuple) {
var text = "";
var members = tuple.members;

for (var idx = 0, length = members.length; idx < length; idx++) {
text += members[idx].name;

if (members[idx + 1]) {
text += "->";
}
}

return text;
}
});
</script>
</div>

瞭解最新Kendo UI最新資訊,請關注Telerik中文網!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章