|
1 | 1 | import dc from 'dc'; |
| 2 | +import dataTeble from 'datatables'; |
2 | 3 |
|
3 | 4 | Template.chartsLayout.rendered = function () { |
4 | 5 |
|
@@ -201,23 +202,50 @@ Template.chartsLayout.created = function () { |
201 | 202 | .renderVerticalGridLines(true) |
202 | 203 | .elasticY(true); |
203 | 204 |
|
204 | | - // Creates Dynatable |
205 | | - var dynatable = $('#dc-data-table').dynatable({ |
206 | | - features: { |
207 | | - pushState: false |
208 | | - }, |
209 | | - dataset: { |
210 | | - records: setUpDataTable(), |
211 | | - perPageDefault: 10, |
212 | | - perPageOptions: [10, 20, 50, 100] |
213 | | - } |
214 | | - }).data('dynatable'); |
| 205 | + // Init datatable |
| 206 | + initDatatable(); |
| 207 | + |
| 208 | + // Init datatable function |
| 209 | + function initDatatable () { |
| 210 | + |
| 211 | + // Get initial or updated table data |
| 212 | + const tableData = setUpDataTable(); |
| 213 | + |
| 214 | + // Save reference to datatable body element |
| 215 | + const datatableBody = $('.datatable tbody'); |
| 216 | + |
| 217 | + // Cleanup datatable if it already has any rows |
| 218 | + datatableBody.empty() |
| 219 | + |
| 220 | + // Iterate through each data item and append a row with data to datatable |
| 221 | + _.each(tableData, (tableItem) => { |
| 222 | + datatableBody.append(` |
| 223 | + <tr> |
| 224 | + <td scope="row">${tableItem.time}</td> |
| 225 | + <td>${tableItem.country}</td> |
| 226 | + <td>${tableItem.path}</td> |
| 227 | + <td>${tableItem.ip}</td> |
| 228 | + <td>${tableItem.response}</td> |
| 229 | + </tr> |
| 230 | + `); |
| 231 | + }); |
| 232 | + |
| 233 | + // Initialize data table |
| 234 | + $('.datatable').dataTable({ |
| 235 | + pagingType: 'simple' |
| 236 | + }); |
| 237 | + } |
215 | 238 |
|
216 | 239 | // Listens to filtering event and refreshes the table on a change |
217 | 240 | function refreshTable() { |
218 | 241 | dc.events.trigger(function () { |
219 | | - dynatable.settings.dataset.originalRecords = setUpDataTable(); |
220 | | - dynatable.process(); |
| 242 | + |
| 243 | + // Destory datatable to drop pagination |
| 244 | + $('.datatable').dataTable().fnDestroy(); |
| 245 | + |
| 246 | + // Fill datatable with updated data |
| 247 | + initDatatable(); |
| 248 | + |
221 | 249 | }); |
222 | 250 | } |
223 | 251 |
|
@@ -273,7 +301,7 @@ Template.chartsLayout.created = function () { |
273 | 301 |
|
274 | 302 | // Error handling for empty fields |
275 | 303 | try{ |
276 | | - timeStamp = e.fields.request_at[0]; |
| 304 | + timeStamp = moment(e.fields.request_at[0]); |
277 | 305 | }catch(e){ |
278 | 306 | timeStamp = ""; |
279 | 307 | } |
@@ -303,7 +331,7 @@ Template.chartsLayout.created = function () { |
303 | 331 | } |
304 | 332 |
|
305 | 333 | dataSet.push({ |
306 | | - "time" : timeStamp, |
| 334 | + "time" : timeStamp.format("D/MM/YYYY HH:mm:ss"), |
307 | 335 | "country" : country, |
308 | 336 | "path" : path, |
309 | 337 | "ip" : requestIp, |
|
0 commit comments