Reputation: 641
I have a records of 15K in my collection with min 40 fields, I created a table which is generated from records. In this table i have various fileds as shown in image(from Excel sheet).
/client/main.js
Template.GetTable.helpers({
'getTotalData':function(key1,key2){
console.log("-------inside totalData()---------");
const projects1 = Template.instance().distinct1.get();
var filter1= _.map(projects1, col_8 => {
return {col_8};
});
q={};
p={};
console.log(filter1);
console.log(JSON.stringify(q));
//var queryData=test.find(q).fetch();
Meteor.call('getCountData',"all",function(err,count){
if(err)
console.log("Failed to call meteor..!");
else{
console.log(count);
return count;
}
});
},
});
/server/main.js
Meteor.methods({
'getCountData':function(type){
return test.find({"col_17" : " Query->:#####->x","col_8": { $regex: /^CQI?/i}}).count();
},
});
I was just testing for testing and i know how to get the count from DB. My problem is after all the rendering and the helpers are called the UI will load without any count data. But when i checked in debugger i got the right counts printed using "console.log()" and the UI is not updated. How can i resolve this issue? or is there any efficient way to solve this?
Upvotes: 0
Views: 164
Reputation: 2863
The UI problem is that you're doing a Meteor calling inside a helper and returning the result of the call to itself, not the helper.
Here's an example of what you're doing and what you SHOULD be doing.
SHOULD NOT:
Template.GetTable.helpers({
'getTotalData':function(key1,key2){
Meteor.call('getCountData',"all",function(err,count){
if(err)
console.log("Failed to call meteor..!");
else {
return count; // Being returned to this function, not helper fuction
}
});
},
});
SHOULD:
var recVar = new ReactiveVar(false);
Template.GetTable.onCreated({
Meteor.call('getCountData',"all",function(err,count){
if(err)
console.log("Failed to call meteor..!");
else {
recVar.set(count);
}
});
});
Template.GetTable.helpers({
'getTotalData':function(key1,key2){
return recVar.get();
},
});
Upvotes: 3