forked from predixdesignsystem/px-data-table
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.html
180 lines (148 loc) · 6.57 KB
/
demo.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>px-data-table Demo</title>
<script src="../webcomponentsjs/webcomponents-lite.min.js"></script>
<link rel="import" href="px-data-table.html" />
<link rel="import" href="../iron-ajax/iron-ajax.html" />
<link rel="import" href="../px-theme/px-theme-styles.html">
<style include="px-theme-styles" is="custom-style"></style>
</head>
<body unresolved>
<template is="dom-bind">
<iron-ajax url="contacts.json" last-response="{{data}}" auto></iron-ajax>
<iron-ajax id="test" url="contacts-mini.json" last-response="{{minidata}}" auto></iron-ajax>
<h3>Data table demos</h3>
<p>A very simple data table. Just displays data and has sortable columns.</p>
<px-data-table show-column-chooser enable-column-resize enable-column-reorder hide-pagination-control table-data="{{minidata}}"></px-data-table>
<hr>
<p>Filterable columns and selectable rows.</p>
<px-data-table filterable selectable table-data="{{data}}"></px-data-table>
<hr>
<p>Display as columns instead of a grid.</p>
<px-data-table table-columns table-data="{{data}}"></px-data-table>
<hr>
<p>Display as rows instead of a grid.</p>
<px-data-table table-rows enable-column-reorder table-data="{{data}}"></px-data-table>
<hr>
<h3>Very customized data table</h3>
<div>
Filtering
<ul>
<li>First column: custom filtering function - filters on an entire word in the First column</li>
<li>Color column: custom filtering function - on the button text in the Color column</li>
</ul>
</div>
<div>
Sorting
<ul>
<li>Selected column: groups all selected columns at the beginning or end</li>
<li>First and Last columns: default sorting alphanumerically</li>
<li>Email column: custom sorting function - by the email domain (gmail, hotmail, yahoo)</li>
</ul>
</div>
<div>
Truncation and ellipsis
<ul>
<li>Image column: left ellipsis, 40 characters maximum</li>
<li>Date column: right ellipsis, 25 characters maximum</li>
</ul>
</div>
<div>
Html rendering
<ul>
<li>Color column</li>
</ul>
</div>
<div>
Interacting with selecting rows
<ul>
<li>there are <span>{{mySelectedRows.length}}</span> rows selected</li>
<li>you can <button onclick="logSelectedRows()">console.log the selected rows</button></li>
<li>listen for px-row-click events from the table, which can be used by taking action on the row</li>
</ul>
</div>
<px-data-table id="mytable" hide-pagination-control selected-rows="{{mySelectedRows}}" enable-column-resizing enable-column-reorder show-column-chooser filterable selectable table-data="{{minidata}}">
<px-data-table-column
name="first"
filterable
sortable
editable
filter-function-name="myTableCustomFunctions.filterWholeWord">
<px-validation>
<px-validator validation-method="isNumber" import="../px-validation/px-example-validator.html"></px-validator>
</px-validation>
<px-data-table-highlight highlight-type="cell" highlight-value="medium" highlight-method="wordBeginsWithLetterJ" import="px-example-highlight.html"></px-data-table-highlight>
<px-data-table-highlight highlight-type="row" highlight-value="high" highlight-method="isLongString" import="px-example-highlight.html"></px-data-table-highlight>
<px-data-table-highlight highlight-type="cell" highlight-value="low" highlight-method="wordBeginsWithLetterS" import="px-example-highlight.html"></px-data-table-highlight>
</px-data-table-column>
<px-data-table-column
name="last"
editable
sortable>
</px-data-table-column>
<px-data-table-column
name="email"
editable
sort-function-name="myTableCustomFunctions.sortByEmailDomain"
sortable>
</px-data-table-column>
<px-data-table-column
name="country"
type="dropdown"
editable
max-column-character-width="14"
dropdown-items='["United Kingdom", "United States of America", "Germany", "Chad", "Seychelles", "Uruguay"]'>
</px-data-table-column>
<px-data-table-column
name="color"
type="html"
filterable
filter-function-name="myTableCustomFunctions.filterMarkupVal">
</px-data-table-column>
<px-data-table-column
name="image"
max-column-character-width="40"
ellipsis-clip-position="left">
</px-data-table-column>
<px-data-table-column
name="date"
max-column-character-width="25"
ellipsis-clip-position="right">
</px-data-table-column>
</px-data-table>
<script>
window.myTableCustomFunctions = {
sortByEmailDomain: function(a, b) {
var aDomain = a.value.substring(a.value.indexOf("@")+1, a.value.indexOf("."));
var bDomain = b.value.substring(b.value.indexOf("@")+1, b.value.indexOf("."));
return this.descending ? (aDomain < bDomain ? 1 : -1) : (aDomain > bDomain ? 1 : -1);
},
filterMarkupVal: function(searchString, cellValue) {
var lhs = cellValue.slice(cellValue.indexOf('>') + 1);
var content = lhs.substr(0, lhs.indexOf('<'));
return (content.toString().toLowerCase().indexOf(searchString.toString().toLowerCase()) > -1);
},
filterWholeWord: function(searchString, cellValue) {
if(searchString === undefined || searchString === null || searchString === "") {
return true;
}
return (searchString.toString().toLowerCase() === cellValue.toString().toLowerCase());
}
};
function logSelectedRows() {
var selectedRows = document.getElementById("mytable").selectedRows;
console.log("Get all selected rows:", selectedRows);
}
document.addEventListener('WebComponentsReady', function() {
document.getElementById("mytable").addEventListener("px-row-click", function(e) {
var clickedRow = e.detail.row;
console.log("Row clicked", clickedRow, " _selected: ", clickedRow._selected);
});
});
</script>
</template>
</body>
</html>