This repository has been archived by the owner on Oct 26, 2022. It is now read-only.
forked from ShellRechargeSolutionsEU/kendo-elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdates.html
197 lines (182 loc) · 6.27 KB
/
dates.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>Kendo Elasticsearch - demos - Basic</title>
<!--<link rel='stylesheet' href='http://kendo.cdn.telerik.com/2014.1.318/styles/kendo.common.min.css'>-->
<link rel='stylesheet' href='../bower_components/kendo-ui/styles/kendo.common.min.css'>
<!--<link rel='stylesheet' href='http://kendo.cdn.telerik.com/2014.1.318/styles/kendo.default.min.css'>-->
<link rel='stylesheet' href='../bower_components/kendo-ui/styles/kendo.default.min.css'>
</head>
<body>
<h1>Kendo Elasticsearch - demos - Dates</h1>
<div id='grid1'></div>
<div id='grid2'></div>
<div id='grid3'></div>
<!--<script src='https://code.jquery.com/jquery-2.1.4.min.js'></script>-->
<script src='../bower_components/jquery/jquery.min.js'></script>
<!--<script src='http://kendo.cdn.telerik.com/2014.1.318/js/kendo.web.min.js'></script>-->
<script src='../bower_components/kendo-ui/src/js/kendo.web.js'></script>
<!--<script src='https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.min.js'></script>-->
<script src='../bower_components/moment/min/moment.min.js'></script>
<script src='../dist/kendo-elasticsearch.js'></script>
<script>
$(document).ready(function() {
var dataSourceOpts = {
transport: {
read: {
url: 'http://localhost:9200/kendo-elasticsearch-demo/person/_search/'
}
},
pageSize: 10,
schema: {
model: {
esMappingKey: 'person',
fields: {
firstName: {
type: 'string',
esFilterSubField: 'lowercase',
esName: 'name.firstName'
},
lastName: {
type: 'string',
esFilterSubField: 'lowercase',
esName: 'name.lastName'
},
birthDate: {
type: 'date'
},
birthDateYear: {
type: 'date',
esName: 'birthDate'
},
birthDateMonth: {
type: 'date',
esName: 'birthDate'
},
birthDateDay: {
type: 'date',
esName: 'birthDate'
},
age: {
type: 'number',
esName: 'birthDate',
duration: 'beforeToday'
}
}
}
},
group: [{
field: "birthDateYear",
dir: "desc",
aggregates: [{
field: "birthDateYear",
aggregate: "date_histogram",
interval: "year"
}]
// see https://www.elastic.co/guide/en/elasticsearch/reference/2.0/search-aggregations-bucket-datehistogram-aggregation.html
// if defined the bucket aggregation will be a date_histogram aggregation
}, {
field: "birthDateMonth",
dir: "desc",
aggregates: [{
field: "birthDateMonth",
aggregate: "date_histogram",
interval: "month"
}]
}, {
field: "birthDateDay",
dir: "desc",
aggregates: [{
field: "birthDateDay",
aggregate: "date_histogram",
interval: "day"
}]
}]
};
// LOOK HERE FOR MISSING AND EXISTS FILTERS
// We override the internal filter function from the filter menu widget in order to accept empty values
// on the specific 'missing' and 'exists' operators
kendo.ui.FilterMenu.prototype.filter = function(expression) {
var field = dataSourceOpts.schema.model.fields[this.field];
expression.filters.forEach(function(filter) {
if (filter.operator === 'exists' || filter.operator === 'missing') {
if (field.type === 'date') {
filter.value = new Date().toISOString();
} else if (field.type === 'string') {
filter.value = '-- ' + filter.operator + ' --'
}
}
});
// The following is the content of the original function
expression = this._merge(expression);
if (expression.filters.length) {
this.dataSource.filter(expression);
}
}
var gridOptions = {
sortable: true,
pageable: true,
filterable: {
extra: true,
operators: {
string: {
search: "Search",
eq: "Is equal to",
neq: "Is not equal to",
startswith: "Starts with",
contains: "Contains",
doesnotcontain: "Does not contain",
endswith: "Ends with",
exists: 'Exists',
missing: 'Missing'
},
date: {
eq: "Is equal to",
neq: "Is not equal to",
gte: "Is after or equal to",
gt: "Is after",
lte: "Is before or equal to",
lt: "Is before",
exists: 'Exists',
missing: 'Missing'
}
}
},
columns: [{
field: 'birthDate',
format: '{0:D}',
title: 'Date of birth'
}, {
field: 'birthDateYear',
hidden: true,
groupHeaderTemplate: "#=kendo.toString(value, 'yyyy')# (#=count#)",
}, {
field: 'birthDateMonth',
hidden: true,
groupHeaderTemplate: "#=kendo.toString(value, 'MMMM')# (#=count#)",
}, {
field: 'birthDateDay',
hidden: true,
groupHeaderTemplate: "#=kendo.toString(value, 'dd')# (#=count#)",
}, {
field: 'firstName',
title: 'First name'
}, {
field: 'lastName',
title: 'Last name'
}, {
field: 'age',
title: 'Age'
}]
};
gridOptions.dataSource = new kendo.data.ElasticSearchDataSource(dataSourceOpts);
$('#grid1').kendoGrid(gridOptions);
/*dataSourceOpts.group.aggregates[0].interval = "month";
gridOptions.columns[0].groupHeaderTemplate = "Month of birth: #=kendo.toString(value, 'MMMM yyyy')#, Count: #=count#"
gridOptions.dataSource = new kendo.data.ElasticSearchDataSource(dataSourceOpts);
$('#grid2').kendoGrid(gridOptions);*/
});
</script>
</body>
</html>