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

How to Update Pager? #89

Closed
gte451f opened this issue Feb 13, 2015 · 8 comments
Closed

How to Update Pager? #89

gte451f opened this issue Feb 13, 2015 · 8 comments

Comments

@gte451f
Copy link

gte451f commented Feb 13, 2015

When using the Remote Paginated API option, I have trouble updating the pager when I've added a new record to the found set.

Put another way, if I just added a record via something like Ember Data, how do I tell the Pager about the new record WITHOUT triggering a full XHR request?

I try adding the record to the store like this...

store.push('document', store.normalize('document', data));

...and while the record shows up on my Ember inspector, the Pager won't show the record.

@knownasilya
Copy link

Since pagedArray proxies the model, if you add records to the model they should be added to the paged list.

// in controller
page: 1,
perPage: 10,
pagedContent: pagedArray('model', { pageBinding: 'page', perPageBinding: 'perPage' }),

actions: {
  addModel: function () {
    var models = this.get('model');
    var model = this.store.createRecord('myModel', {
      fun: true,
      foo: 'bar'
    });

    model.save()
      .then(function () {
        // might not be necessary if you got the models via store.find('myModel')
        models.addRecord(model);
      }, function (error) {
        console.error(error);
      });
  }
}

@gte451f
Copy link
Author

gte451f commented Mar 3, 2015

I've tried this a few different ways but no joy.

// errors out that addRecord is undefined.
models.addRecord()


// this works fine on a regular model, but I get...
// The result of a server query (on BADASSAPP@model:document:) is immutable.
// pagedArray
var models = this.get('model');
var doc = {
    name: 'my name',
    size: 23
};
var model = this.store.createRecord('document', doc);
models.pushObject(model);

I suspect the pagedArray being remote (in my case) prevents me from adding/remove records to/from it?

@gte451f
Copy link
Author

gte451f commented Mar 10, 2015

Ok, here is a working example

// add to models.content.addRecord instead
var models = this.get('model');
var doc = {
    name: 'my name',
    size: 23
};
var model = this.store.createRecord('document', doc);
models.content.addRecord(model);

@gte451f gte451f closed this as completed Mar 10, 2015
@knownasilya
Copy link

@gte451f which shouldn't be, since there should be a proxy @mharris717

@vasilakisfil
Copy link

Not working for me not matter what. Tried get('models.content').pushObject(model), get('models.content.content').pushObject(model), get('models.content').addRecord(model) and get('models.content.content').addRecord(model) all fail.

@vasilakisfil
Copy link

There should definitely be a way to push records to PagedRemoteArray :)

@williamweckl
Copy link

Did not work for me either.

My code:

      return adapter.ajax(url, 'POST', {
        email: email
      }).then(function(data) {
        var normalized = store.normalize(modelName, data.object);
        store.push(normalized); //works with this.store.findAll
      });
model(params) {
    return this.findPaged('billing/delivery-file',params); //paginated not working push to store
    // return this.store.findAll('billing/delivery-file'); (this works)
  }

@williamweckl
Copy link

@vasilakisfil did you got any working solution?

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

4 participants