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

[RFR] Introducing filter default value #639

Merged
merged 1 commit into from
Sep 1, 2015
Merged

Conversation

fzaninotto
Copy link
Member

You can now use defaultValue() on filter fields, so as to filter the list as soon as the filter is added. Combined with an empty template, this allows to create "tagged" lists:

var user_id = 123; // currently logged user
var d = new Date()
var yesterday = d.setDate(d.getDate() - 1);
listView.filters([
    nga.field('flagged', 'template')
        .defaultValue('true'), // adds ?flagged=true to the REST query
    nga.field('author_id', 'template')
        .label('Mine')
        .defaultValue(user_id), // adds ?author_id=123 to the REST query
    nga.field('created_at', 'template')
        .label('Recent')
        .defaultValue({ gt: yesterday }), // adds ?created_at={gt:2015-08-31} to the REST query
]);

@@ -33,10 +32,15 @@ function maFilterDirective(FieldViewConfiguration) {
scope: {
filters: '=',
datastore: '&',
values: '&'
values: '&',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a mystery that I can't explain: values uses one-way databinding in an isolated scope, yet the watcher on ListLayoutController gets notified when the values change. Weird, but works.

fzaninotto added a commit that referenced this pull request Sep 1, 2015
[RFR] Introducing filter default value
@fzaninotto fzaninotto merged commit 6b308ae into master Sep 1, 2015
@fzaninotto fzaninotto deleted the filter_default_value branch September 1, 2015 08:48
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

Successfully merging this pull request may close these issues.

None yet

1 participant