Okay, so what u showed me before is perfectly working, i achieved what i wanted to do.
Perhaps now, with this, i’m trying to build a function which will determinate which operator i should use for my filter. Actually, i’m doing something like this :
filter_operator: function (operator, filter, val) {
// console.log('hello world : ' + operator);
var complete_filter = {};
switch (operator) {
case "equalTo":
complete_filter = {[filter]: { $eq: val}};
break;
case "isDifferentFrom":
complete_filter = {[filter]: { $ne: val}};
break
case "contain":
complete_filter = {[filter]: { $regex: '.*' + val + '.*' }};
break
// NOT DONE YET ///////////////
case "doNotContain":
complete_filter = {[filter]: { $eq: val}};
break
case "isSet":
complete_filter = {[filter]: { $eq: val}};
break
case "isNotSet":
complete_filter = {[filter]: { $eq: val}};
break
// NOT DONE YET ///////////////
default:
break;
}
console.log(operator);
console.log(complete_filter);
return complete_filter;
},
This function is défined into Meteor.methods, i’m able to call her at the moment.
Perhaps, i’m not sure about the operators. It’s actually apparently doing something, but there is no collection data displayed when it should be.
I, for example, have a record with a “label” that contains Test 1. Without this function, it was perfectly working. Where is the mistake ?
Here is the output of console.log(complete_filter) :
{label: {…}}
label: {$regex: ".*Test.*"}
It seems to be ok to me ?
Here is my new event :
'click .tw-filter-submit': function (events, template) {
// swal("Ooops !", "This function is not available yet !", "info");
var filterOperator = $('#crmFilterOperator').val();
var selectFilter = $("#crmFilterSelect").val();
var filterVal = $(".tw-filter-input").val();
Template.instance().filtersVar.set(Meteor.call('filter_operator', filterOperator, selectFilter, filterVal))
},
Thanks a lot in advance !
PS : If needed, here’s the rest of the JS :
// SUBSCRIBE TO PIPELINES PUBLICATIONS ON TEMPLATES
Template.crmTreeView.onCreated(function () {
var self = this;
self.autorun(function () {
self.subscribe('Pipelines');
var filters = [];
for (var key in Pipelines.findOne({})) {
// console.log(key);
filters.push(key);
}
console.log(filters);
});
if (FlowRouter.getParam('page')) {
var page = FlowRouter.getParam('page');
}
// Here we build the instance to set variables
const instance = this;
// This var will allow us to use filters on collection, with events and helpers
instance.filtersVar = new ReactiveVar({});
});
// LOAD DATA ON TEMPLATES
Template.crmTreeView.helpers({
pipelines: () => {
// here we return data according on our filters. If no filter, filtersVar is an empty object
// so we will get all the data
return Pipelines.find(Template.instance().filtersVar.get(), { limit: 10 });
},
collection_key: () => {
var filters = [];
for (var key in Pipelines.findOne({})) {
filters.push(key);
}
return filters;
}
});