forked from Neovici/cosmoz-omnitable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcosmoz-omnitable-column-number.html
105 lines (95 loc) · 3.32 KB
/
cosmoz-omnitable-column-number.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
<link rel="import" href="../iron-flex-layout/iron-flex-layout.html">
<link rel="import" href="../paper-input/paper-input.html">
<link rel="import" href="../paper-dropdown-menu/paper-dropdown-menu.html">
<link rel="import" href="../cosmoz-i18next/cosmoz-i18next.html">
<link rel="import" href="ui-helpers/cosmoz-clear-button.html">
<link rel="import" href="cosmoz-omnitable-column-behavior.html">
<link rel="import" href="cosmoz-omnitable-column-range-behavior.html">
<dom-module id="cosmoz-omnitable-column-number">
<template>
<template class="cell">
<div class="omnitable-cell-number">[[ getString(item, valuePath, formatter) ]]</div>
</template>
<template class="edit-cell">
<paper-input no-label-float type="number" on-change="_valueChanged" value="[[ getInputString(item, valuePath) ]]"></paper-input>
</template>
<template class="header">
<cosmoz-clear-button on-click="resetFilter" visible="[[ hasFilter(filter.*) ]]"></cosmoz-clear-button>
<paper-dropdown-menu label="[[ title ]]" placeholder="[[ _filterText ]]" title="[[ _tooltip ]]"
horizontal-align="[[ preferredDropdownHorizontalAlign ]]" opened="{{ headerFocused }}">
<div class="dropdown-content" slot="dropdown-content" style="padding: 15px; min-width: 100px;">
<h3 style="margin: 0;">[[ title ]]</h3>
<paper-input type="number" label="[[ _('From', t) ]]" value="{{ _filterInput.min }}"
min="[[ _toInputString(_limit.fromMin) ]]" max="[[ _toInputString(_limit.fromMax) ]]">
</paper-input>
<paper-input type="number" label="[[ _('To', t) ]]" value="{{ _filterInput.max }}"
min="[[ _toInputString(_limit.toMin) ]]" max="[[ _toInputString(_limit.toMax) ]]">
</paper-input>
</div>
</paper-dropdown-menu>
</template>
</template>
<script>
Polymer({
is: 'cosmoz-omnitable-column-number',
behaviors: [
Cosmoz.OmnitableColumnBehavior,
Cosmoz.TranslatableBehavior,
Cosmoz.RangeColumnBehavior
],
properties: {
cellClass: {
type: String,
value: 'number-cell align-right'
},
width: {
type: String,
value: '30px'
},
editWidth: {
type: String,
value: '30px'
},
headerCellClass: {
type: String,
value: 'number-header-cell'
},
maximumFractionDigits: {
type: Number,
value: null
},
minimumFractionDigits: {
type: Number,
value: null // browser default 0 for numbers, currency-specific or 2 for currency
},
formatter: {
type: Object,
computed: '_computeFormatter(locale, minimumFractionDigits, maximumFractionDigits)'
},
_filterText: {
type: String,
computed: '_computeFilterText(filter.*, formatter)'
}
},
_computeFormatter(locale, minimumFractionDigits, maximumFractionDigits) {
const options = {
localeMatcher: 'best fit' // chrome expects this when using custom options
};
if (minimumFractionDigits !== null) {
options.minimumFractionDigits = minimumFractionDigits;
}
if (maximumFractionDigits !== null) {
options.maximumFractionDigits = maximumFractionDigits;
}
return new Intl.NumberFormat(locale || undefined, options);
},
renderValue(value, formatter = this.formatter) {
const number = this.toNumber(value);
if (number == null) {
return;
}
return formatter.format(number);
},
});
</script>
</dom-module>