8000 Creating data · Issue #237 · mharris717/ember-cli-pagination · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Creating data #237

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

Open
MichalBryxi opened this issue Feb 11, 2018 · 1 comment
Open

Creating data #237

MichalBryxi opened this issue Feb 11, 2018 · 1 comment

Comments

@MichalBryxi
Copy link
Contributor
MichalBryxi commented Feb 11, 2018

I'm completely missing a hint that would describe how to handle the case when user adds new data into currently paginated data set. My case would be:

  1. The page displays list of paginated records
  2. User creates & saves new record
  3. The record is immediately visible in the list of paginated records (assuming that it should be displayed given it's position in paginated data)

I think I found a nice solution which is unfortunately not documented anywhere:

// route.js
export default Route.extend(RouteMixin, {
  model() {
      return this.findPaged('post'),
  }
});
// controller.js
export default Controller.extend({
  actions: {
    createNewPost() {
      // Note that this by itself won't make the post appear in paginated list of posts
      let newPost = this.store.createRecord('post'); 

      // Not even saving the data server side will make it appear on user's screen
      return newPost.save().then(() => { 
        // This will force the ember-cli-pagination to re-fetch current page
        this.get('model').setOtherParam('nameOrValueOfThisPropertyDoesNotReallyMatter', true); 
      });
    }
  }
});
{{! template.hbs }}

<button {{action "createNewPost"}}>Click me to create new post</button>

<ul>
  {{#each model as |post|}}
    <li>{{post.id}}</li>
  {{/each}} 
</ul>

Not: I'm writing that from the top of my head. Might not 100% compile.

Hope this might help somebody. Also if this snippet is correct, it would be nice to have it as part of the documentation.

@broerse
Copy link
Collaborator
broerse commented Feb 11, 2018

Help is always welcome. Perhaps do a PR?

MichalBryxi added a commit to MichalBryxi/ember-cli-pagination that referenced this issue Feb 11, 2018
- Simple example on how-to reload data from the server when we know that we need it.
broerse added a commit that referenced this issue Feb 12, 2018
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
0