Hi all,
I’ve been trying to implement DataTables (without any package - aldeed:tabular gets stuck on processing and crashes the browser) and using DOM as the source of data. However, I get “No data available in the table”. Is there any obvious reason why it can’t pick the DOM data?
I have this on my HTML file:
<head>
<title>Logins</title>
</head>
<body>
<h1>Logins</h1>
{{> loginButtons}}
{{> loginstemplate}}
</body>
<template name="loginstemplate">
{{#if ready}}
<h1>External users logged in: {{countusers}}; Active: {{countactiveusers}}</h1>
<table id="example" class="display" width="70%">
<thead>
<tr>
<th>Username</th>
<th>Logged in?</th>
<th>Name</th>
<th>Firm</th>
<th>Region</th>
<th>Login time</th>
<th>Record type</th>
</tr>
</thead>
<tbody>
{{#each getlogin}}
<tr>
<td>{{Username}}</td>
<td>{{#if registeredatcheck}} Y {{/if}}</td>
<td>{{Name}}</td>
<td>{{Firm}}</td>
<td>{{Region}}</td>
<td>{{formatDate RegisteredAt}}</td>
<td>{{Recordtype}}</td>
</tr>
{{/each}}
</tbody>
</table>
{{/if}}
</template>
And my JS file:
import { Template } from 'meteor/templating';
Logins = new Mongo.Collection('logins');
if(Meteor.isClient){
Meteor.subscribe('getlogins');
var $ = require( 'jquery' );
var dt = require( 'datatables.net' )( window, $ );
Template.loginstemplate.helpers({
'ready': function () {
return Template.instance().subscriptionsReady();
// $('#example').DataTable();
},
'getlogin': function(){
return Logins.find({});
},
'countusers': function(){
return Logins.find({"RegisteredAt":{$ne:'N/A'}}).count();
},
'countactiveusers': function(){
return Logins.find().count();
},
'registeredatcheck': function(){
return this.RegisteredAt instanceof Date;
}
});
$(document).ready(function() {
$('#example').DataTable();
} );
Template.registerHelper('formatDate', function(date) {
if (this.RegisteredAt instanceof Date){
return moment.utc(date).format('D MMM YYYY h:mm A');
}
});
}