Closed Dev24Patrick closed 5 years ago
Hi,
To update the filters automatically you should call filters()
method inside a Tracker autorun. For example:
Template.myList.onCreated(function () {
this.search = new ReactiveVar("");
this.typeOfEntry= new ReactiveVar("");
this.pagination = new Meteor.Pagination(damage, {
filters: {}, // you can also set an initial filter here
sort: {
createdAt: 1,
}
});
this.autorun(() => {
// change filter every time one of the reactive vars change
const filter = {
barcode: {
$regex: this.search.get()
},
typeOfEntry:{
$regex: this.typeOfEntry.get()
},
completed: true,
};
if (!isAdminForFilter === true){
filter.companyId = {
$regex: cmpyIdForFilter
};
}
this.pagination.filters(filter);
});
});
Although if you want to add an additional company filter if user is not an admin you should use the server side dynamic_filters
or transform_filters
options when initializing the pagination.
Hi,
thanks for this help. It works fine :)
At leat one question. Is there something different by the filter to search between a date?
Example:
let timestampFrom = (new Date(this.filterFrom.get())).getTime(); let timestampTo = new Date(this.filterTo.get()); timestampTo.setHours(23); timestampTo.setMinutes(59); timestampTo.setSeconds(59); timestampTo = timestampTo.getTime();
filter = { barcode: { $regex: this.search.get() }, typeOfEntry:{ $regex: typeOfEntry.get() }, createdAt:{ "$gte": timestampFrom, "$lt": timestampTo }, deletedAt: false, completed: true, }
Thanks for your help
Best regards Patrick
Gesendet: Freitag, 16. November 2018 um 16:23 Uhr Von: Kurounin notifications@github.com An: Kurounin/Pagination Pagination@noreply.github.com Cc: Dev24Patrick PWamser@gmx.de, Author author@noreply.github.com Betreff: Re: [Kurounin/Pagination] Search in all Pages from Pagination (#91)
Hi,
To update the filters automatically you should call filters() method inside a Tracker autorun. For example:
Template.myList.onCreated(function () { this.search = new ReactiveVar(""); this.typeOfEntry= new ReactiveVar("");
this.pagination = new Meteor.Pagination(damage, {
filters: {}, // you can also set an initial filter here
sort: {
createdAt: 1,
}
});
this.autorun(() => {
// change filter every time one of the reactive vars change
const filter = {
barcode: {
$regex: this.search.get()
},
typeOfEntry:{
$regex: this.typeOfEntry.get()
},
completed: true,
};
if (!isAdminForFilter === true){
filter.companyId = {
$regex: cmpyIdForFilter
};
}
this.pagination.filters(filter);
});
});
Although if you want to add an additional company filter if user is not an admin you should use the server side dynamic_filters or transform_filters options when initializing the pagination.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.
If you're storing createdAt
as a number, then your query is correct. If you're storing it as a date you should use dates to filter:
createdAt:{
"$gte": newDate(timestampFrom),
"$lt": new Date(timestampTo)
},
Hi,
i fixed this problem and your package works perfect, thanks for this great job!
i only have one question, maybe you have an idea how to realize this with your package:
current publish:
Meteor.publish('users', function() { if ( !this.userId ) return this.ready(); let user = Meteor.users.findOne(this.userId);
if ( user.profile.admin === true) { return Meteor.users.find(); } else { if (user.emails[0].address === null || user.emails[0].address === undefined){ return this.ready(); } else{ return Meteor.users.find(); } } });
publish with your package:
?
thanks for your help
regards Patrick
Gesendet: Montag, 19. November 2018 um 19:58 Uhr Von: Kurounin notifications@github.com An: Kurounin/Pagination Pagination@noreply.github.com Cc: Dev24Patrick PWamser@gmx.de, Author author@noreply.github.com Betreff: Re: [Kurounin/Pagination] Search in all Pages from Pagination (#91)
If you're storing createdAt as a number, then your query is correct. If you're storing it as a date you should use dates to filter:
createdAt:{
"$gte": newDate(timestampFrom),
"$lt": new Date(timestampTo)
},
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.
To accomplish that you can use the dynamic_filters
option on server side:
publishPagination(MyCollection, {
dynamic_filters: function () {
if ( !this.userId ) {
return { _id: 0 }; // apply an impossible filter to not return anything
}
const user = Meteor.user();
if ( user.profile.admin === true) {
return {}; // do not apply any additional filters to execute find with existing filters
} else {
if (user.emails[0].address === null || user.emails[0].address === undefined){
return { _id: 0 }; // apply an impossible filter to not return anything
}
else{
return {}; // do not apply any additional filters to execute find with existing filters
}
}
},
});
Hi, i'm using this Pagination and it works very good.
I have a question for filtering over all on client side. i'm using this code:
client side (test.js):
if (isAdminForFilter === true){
var dataForCheck = Template.instance().pagination.getPage();
Is it possible to search and filter directly and automatic refresh from the pagination list on client side?
Thanks fpr your help