Skip to content

[RFR] Introducing filter default value#639

Merged
fzaninotto merged 1 commit intomasterfrom
filter_default_value
Sep 1, 2015
Merged

[RFR] Introducing filter default value#639
fzaninotto merged 1 commit intomasterfrom
filter_default_value

Conversation

@fzaninotto
Copy link
Copy Markdown
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
]);

Copy link
Copy Markdown
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.

1 participant