Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client filtering doesn't work! ([email protected] + alethes:[email protected]) #209

Open
thekuzia opened this issue May 12, 2016 · 2 comments

Comments

@thekuzia
Copy link

My code:

/lib/conf/pages.js

Pages = new Meteor.Pagination(Posts, {
    availableSettings: {
            filters: true,
            sort: true,
            limit: true,
        },
    itemTemplate: 'post',
    perPage: 10,
    sort: {
        createdAt: -1,
    },
});

/client/app/home.js

Tracker.autorun(function(){
    Pages.set({
        filters: {
            post_type: Session.get('ses_filter_post_type'),
        },
    });
});

Template.home.events({
    'click .js_filter_post_type': function(e){
        e.preventDefault();

        Session.set('ses_filter_post_type', $(e.target).data('value'));
    },
});

What am I doing wrong?
Thanks.

@thekuzia
Copy link
Author

Thanks a lot to @fletchtj and this issue #131.
I modified my code a bit, and its works!
With auth function - returns only owners posts, and client filtering is work nice.

My code:

/lib/conf/pages.js

Pages = new Meteor.Pagination(Posts, {
    itemTemplate: 'post',
    perPage: 10,
    sort: {
        createdAt: -1,
    },
    filters: {},
    availableSettings: {
        filters: true,
    },

    auth: function(skip, sub){
        if(!sub.userId){ return false; }
        var owner = Meteor.users.findOne({ _id: sub.userId }),
            userSettings = PostPages.userSettings[sub._session.id] || {},
            uFilters = userSettings.filters || this.filters,
            uFields = userSettings.fields || this.fields,
            uSort = userSettings.sort || this.sort,
            uPerPage = userSettings.perPage || this.perPage,
            _filters = _.extend({owner: sub.userId}, uFilters),
            _options = { fields: uFields, sort: uSort, limit: uPerPage, skip: skip };
        return [ _filters, _options ];
    },

});

@abate
Copy link

abate commented Mar 28, 2018

I've also noticed, that it does not work if you don't specify which fields you want to fetch. You can do it with the auth function, or you can specify fields: { "username": 1, "emais.0.address": 1 } in you inital page definition. Without it, the code is going to generate a query with {fields: {} } resulting in an (almost) empty result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants