I'm trying to fix some issue with an ExtJs website but not sure how to proceed. Basically, I have a form that loads an Ext.data.Store model. For new models, the model object initially doesn't have an ID. Once it's saved an ID is assigned to it by the webservice.
The problem is that this Ext.data.Store model is not being reloaded after saving, so it stays without an ID, which causes some problems later on.
So is there any way to force ExtJs to reload the store model after saving? I checked the documentation of Ext.data.Store but cannot see any "reload()" or "refresh()" method. Any suggestion?
You don't need to do anything special. ExtJs has a logic to replace models with phantom flag with the new copies received from the store after update procedure. Chec couple things:
Make sure you have correctly specified idProperty in the model. This is how ExtJs will detect whether record is new or not.
Make sure your store returns properly new/updated records in the response message.
Make sure your data reader properly parses these records in the response message.
Related
I'm trying to do something fun: I'd like to send the record changes from one client to another and have the second client updated to show these changes. Basically collaborative viewing. The second client is disabled from making changes, he can only watch.
Simple fields like strings, numbers, checkboxes, etc. are easy, that worked right away.
The references are the problem. If I have a combo that uses another model as it's source, I am unable to update it on the second client.
I tried setting just the id, then the entire referenced object, I tried various set options, but simply no dice.
The record does change, I see that the data is updated, I was even able to manually modify the _ reference attributes, but the UI keeps showing the old values for those fields.
Is there a way to send the record from one client to another and have the other client just take over all values and display them in the UI? (it would be better to send just the changes, but I'd be very happy if I could get it to work with the entire record)
EDIT: I'm using SailsJS with socket.io, so the p2p connection is not the issue.
I'm getting the data like this:
var data = record.getData(true);
broadcastRecord(data);
And on the other side I tried:
record.set(data);
A code example for the receiving side would be appreciated, if anyone has an ide how to solve this...
I think your problem is related to associations and comboboxes.
Let's say you have a model User with a field group that references model Group, and that you have a User form with a Group combobox.
In the receiver client, you are probably getting only the group id. record.set(data) updates the bound combobox calling setValue(groupId).
This setValue will try to find the corresponding record inside its store, but it won't ask server-side for that record. Instead, it will create a new record with the passed id (showing an empty combobox).
If possibile, you can set remoteFilter:false to the store and queryMode:'local' on the combobox and preload all the data from that store.
Otherwise, I think you'll have to override the combobox setValue method to get the record remotely.
I'm using the server side pagination and filtering example with angularjs.
On loading the data in grid, I would like to programmatically set the first row.
However below method does not work if the grid data has been set using data source.
$scope.gridOptions.api.selectIndex
doesn't work with datasource.
It only works after using the $scope.gridOptions.api.setDataSource
I've also opened an issue in github. Below is the link:
https://github.com/ceolter/ag-grid/issues/601
Please help in resolving this issue.
This is to be expected.
The datasource is the object that will provide your server's data.
As long the datasource is not loaded and did not load the 1st datas you can't use selectIndex method since there is nothing to select.
As a workaround i add myself a custom option in gridOptions where you can provide what you want to select at the 1st loading and select them once my data are loaded the 1st time in my datasource. I add another callback to be able to compare datas and another when the data is not found.
If you want something simplier you can pass to your datasource a promise that will be resolved once the 1st data get loaded (resolve it after call params.successCallback(data) !)
Note : the callback params.successCallback(data) to send the new data to the grid from the datasource must be called before using selectIndex whatever the solution you use.
I'm trying to get an Associated Model (E.g. groups and associated users) from a store with:
Ext.each(this.getView().getSelection()[0].getAssociatedData().users,function(element){
var theuser = myStore.getById(element.id);
theuser.set('deactivated','true');
}
This works for the first 25 Users (id 1-25) however the store is filtered through a pagination plugin. In reason of the filtering with offset and limit the requested id isn't in the local store.
any idea on how to force the store to get the model from remote in case the id isn't available in the local cache?
Or is it anyhow possible to use the data from getAssociatedData, change something and write the record back through the writer proxy?
thx, I really appreciate your help!
The store's getById() method will only return the locally-available records.
If you want to retrieve a model, and you know the id already, you can simply do <model class>.load(id). (If the model is unknown, you can do myStore.getModel().load(id)
Note that the load method returns immediately, but it returns a stub - you'll want to use a callback to process the change to the deactivated field.
In ExtJS5, the Session support will help ensure that the models referred to in both the association store and your myStore object refer to the same model instance.
I'm just getting my head around BackboneJS, but one of the (many) things I'm still struggling with is how exactly the Models Sync up and relate to the serverside DB records.
For example, I have a Model "Dvd", now I change an attribute on the "Dvd" Model, the Name for example, and then I call save(), how exactly does the server side know what DB record to update? Does Backbone hold the DB row ID or something else?
Yes, typically you will set up your Backbone models so that they have database row IDs for any objects you're working with. When one of them is brand new on the client side and not yet saved to the server, it will either have a default or no ID, which doesn't matter since the server will be assigning the ID if and when the initial save transaction succeeds.
Upon saving or updating a model item, Backbone expects the server to reply with some JSON that includes any attributes that have changed since the save or update request was made. In the response to the initial save request, the server informs the client of a newly saved item's row ID (and you can also send along any other information you might need to pass to the client at the same time).
By default, the 'id' attribute of a model object is assumed to be its unique identifier, but backbone lets you change this if you're using a different identifier for the primary key. Just give your model an idAttribute parameter (see the docs for Backbone.Model.extend()) to do that.
Meanwhile, either the urlRoot parameter or a url function can be given to your models to characterize the urls that should be used to send the various ajax requests to the server for a given model.
I have an Ext 3.4 grid with stateful:true, a stateId, and each column in the column model has an id.
Yet when I resize columns I don't see any state cookie saved, and the column widths are not restored when the page is reloaded.
I do have a state Manager with cookie provider defined and I can set/get cookie values via the state manager just fine.
I also added handlers for beforestatesave and statesave and they are being called, but still - no cookie is saved and no state restored. Those handlers are being passed the correct arguments as well - the columns argument show correct updated widths when dumped into the console.
My question is: am I doing something wrong? Should I not expect this to be automatic?
Do I actually have to use those state events to manually save and restore state?
I ran into this problem myself and I figured it out only after about 2 hours of hair pulling.
Do you happen to have a rather large grid? If the cookie data exceeds 4k, which it will easily do if you have 20+ columns of data, it will not save. It will not error either.
I suppose the only other option here would be to go to a different state provider. I'm going to look at the httpProvider that Saki has graciously provided as an alternative.
EDIT:
I've tried to override the provider and remove the string escaping when saving the cookie. This reduces the size by about 50%. I cannot seem to consume it when trying to restore though. I'm certain that the Ext authors were doing this for a reason, otherwise it wouldn't make sense because it inflates the cookie by so much. So much for a hack.
To make a GridPanel stateful I just added stateful: true to the config and setup my provider right before I create any objects
Ext.state.Manager.setProvider(new Ext.state.CookieProvider({
expires: new Date(new Date().getTime()+(1000*60*60*24*30)) // 30 days
}));
I've not tested if it remembers width but try moving columns and the sort order and see if they are being remembered.