Skip to content

Commit 9cc1159

Browse files
committed
docs: Add Show Spreadsheet selection in a Tooltip Spreadsheet how-to
1 parent b0382a3 commit 9cc1159

File tree

1 file changed

+155
-0
lines changed

1 file changed

+155
-0
lines changed
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
---
2+
title: Display the selected range in a Kendo UI Tooltip
3+
page_title: Display the Selected Range in a Kendo UI Tooltip | Kendo UI Spreadsheet
4+
description: "Learn how to display the selected range in a Kendo UI Tooltip."
5+
slug: howto_display_the_selected_range_in_a_tooltip_spreadsheet_widget
6+
---
7+
8+
# Display the selected range in a Kendo UI Tooltip
9+
10+
The example below demonstrates how to display the selected range from a Kendo UI Spreadsheet in a Kendo UI Tooltip, in an AngularJS application.
11+
12+
To achieve the functionality, demonstrated in the example below, follow these steps:
13+
14+
1. Wrap the Spreadsheet in a [`Kendo UI Tooltip`](http://docs.telerik.com/kendo-ui/controls/layout/tooltip/overview)
15+
2. Use the "**k-spreadsheet-selection**" class as [`filter`](/api/javascript/ui/tooltip#configuration-filter) in the Tooltip configuration options
16+
3. Use the [`content`](/api/javascript/ui/tooltip#configuration-content) option to provide a function that will create the content for the Tooltip, based on the current Spreadsheet selection
17+
4. Use the Sheet [`selection()`](/api/javascript/spreadsheet/sheet#methods-selection) method to get the current selection (returns a range), and the Range [`values()`](/api/javascript/spreadsheet/range#methods-values) method to get the respective values
18+
19+
###### Example
20+
21+
```html
22+
23+
<div id="example" ng-app="KendoDemos">
24+
<div ng-controller="MyCtrl">
25+
<kendo-tooltip k-options="ttOptions">
26+
<kendo-spreadsheet k-scope-field="spreadsheet" options="ssOptions"></kendo-spreadsheet>
27+
</kendo-tooltip>
28+
</div>
29+
</div>
30+
31+
<style>
32+
.tooltip-result, .tooltip-result td {
33+
border-collapse: collapse;
34+
border: 1px solid white;
35+
white-space: nowrap;
36+
}
37+
</style>
38+
39+
<script>
40+
var crudServiceBaseUrl = "//demos.telerik.com/kendo-ui/service";
41+
angular.module("KendoDemos", [ "kendo.directives" ])
42+
.controller("MyCtrl", function($scope){
43+
44+
$scope.ttOptions = {
45+
filter: 'div.k-spreadsheet-selection',
46+
content: function(e){
47+
var selectedValues = $scope.spreadsheet.activeSheet().selection().values();
48+
49+
var result = '<table class="tooltip-result"><thead>Selection:</thead>';
50+
selectedValues.forEach(function(item){
51+
result += '<tr>'
52+
item.forEach(function(subItem){
53+
result += ('<td>' + subItem + '</td>');
54+
})
55+
result += '</tr>'
56+
});
57+
58+
result += '</table>';
59+
return result;
60+
},
61+
show: function(e){
62+
e.sender.refresh();
63+
}
64+
};
65+
66+
$scope.ssOptions = {
67+
columns: 20,
68+
rows: 100,
69+
toolbar: false,
70+
sheetsbar: false,
71+
sheets: [{
72+
name: "Products",
73+
dataSource: {
74+
transport: {
75+
read: {
76+
url: crudServiceBaseUrl + "/Products",
77+
dataType: "jsonp"
78+
},
79+
update: {
80+
url: crudServiceBaseUrl + "/Products/Update",
81+
dataType: "jsonp"
82+
},
83+
destroy: {
84+
url: crudServiceBaseUrl + "/Products/Destroy",
85+
dataType: "jsonp"
86+
},
87+
create: {
88+
url: crudServiceBaseUrl + "/Products/Create",
89+
dataType: "jsonp"
90+
}
91+
},
92+
batch: true,
93+
schema: {
94+
model: {
95+
id: "ProductID",
96+
fields: {
97+
ProductID: { type: "number" },
98+
ProductName: { type: "string" },
99+
UnitPrice: { type: "number" },
100+
Discontinued: { type: "boolean" },
101+
UnitsInStock: { type: "number" }
102+
}
103+
}
104+
}
105+
},
106+
rows: [{
107+
height: 40,
108+
cells: [
109+
{
110+
bold: "true",
111+
background: "#9c27b0",
112+
textAlign: "center",
113+
color: "white"
114+
},{
115+
bold: "true",
116+
background: "#9c27b0",
117+
textAlign: "center",
118+
color: "white"
119+
},{
120+
bold: "true",
121+
background: "#9c27b0",
122+
textAlign: "center",
123+
color: "white"
124+
},{
125+
bold: "true",
126+
background: "#9c27b0",
127+
textAlign: "center",
128+
color: "white"
129+
},{
130+
bold: "true",
131+
background: "#9c27b0",
132+
textAlign: "center",
133+
color: "white"
134+
}]
135+
}],
136+
columns: [
137+
{ width: 100 },
138+
{ width: 415 },
139+
{ width: 145 },
140+
{ width: 145 },
141+
{ width: 145 }
142+
]
143+
}]
144+
};
145+
})
146+
</script>
147+
```
148+
149+
## See Also
150+
151+
Other articles on the Kendo UI Spreadsheet:
152+
153+
* [Spreadsheet JavaScript API Reference](/api/javascript/ui/spreadsheet)
154+
* [How to Bind Charts to Sheet Data]({% slug howto_bindcharttosheet_spreadsheet_widget %})
155+
* [How to Set Validation Rules to Column Ranges]({% slug howto_validationtocolumn_spreadsheet_widget %})

0 commit comments

Comments
 (0)