Let's say I have a ExtJs Grid that utilizes a JsonStore for a dataset like:
{
mode: 'piggy',
records: [
{name: 'record1',...},
{name: 'record2',...}
]
}
rooting at records, the grid displays fine. Now is it possible that I can access the "mode" property from the store object? It contains some metadata about my grid beside the row data, and it certainly seems like a waste to open another Ajax connection to the server to get a metadata value. Anyone has done that?
You should still have access to the raw JSON data that came back in the response.
There are probably multiple ways to get to it but here is one:
store.proxy.reader.rawData or jsonData
Related
I have a react-admin Create View that I want to display and populate using ArrayInput which however seems to ignore the data of the list.
I tried to load the data with
const { data } = useQueryWithStore({
type: 'getList',
resource: 'comments',
});
and to set the source to it manually, but the ArrayInput seems unimpressed by all efforts to feed it some data.
I can iterate through the data array and render TextFields and remove buttons accordingly, while leaving the ArrayInput for adding new data, but that defeats the purpose and the beautiful interaction with ArrayInput. Is there something I'm missing? How should I pass the data for it to work as one would expect? I made a sandbox example for this HERE
For creating multiple rows of the entity with one form submit you will need a custom implementation or a work-around.
One of the most esiest ways could be to handle manually the submission of the form and alter the data and send separate requests for each entered entity.
Here in the docs is shown an example how you can pass the Create view a custom toolbar where you can implement your logic.
I have the following store in my Sencha Touch 2.4.1 application:
Ext.define('NativeApp.store.Item', {
extend: 'Ext.data.Store',
config: {
model: 'NativeApp.model.Item',
storeId: 'item-store',
fields: ['id', 'description'],
proxy: {
type: 'ajax',
url: 'resources/json/item.json',
reader: {
type: 'json',
rootProperty: 'items'
}
},
autoLoad: true
}
});
It's being populated with everything in the JSON file, which let's say looks like this:
{
"items": [
{
"id": 's1',
'description': 'desc'
},
{
"id": 's2',
'description': 'desc'
}
]
}
Let's say that in my view I have two buttons, "s1" and "s2".
If I click on "s1", I am taken to a page with a list that contains the data with id "s1". (In this case, there is only one, but there could be more).
How would this be accomplished?
Idea 1:
The autoload attribute can be set to an Object. From here - "If the value of autoLoad is an Object, this Object will be passed to the store's load() method."
So if in my controller, in the handler that's executed when the button is tapped, I can generate this object (parse the JSON file) and somehow pass it to the store - mission accomplished. Sort of.
Besides the question of how to pass it to the store, the immediate problem is when is the data loaded into the store?
According to the docs, "this store's load method is automatically called after creation". Is creation when the app launches, or when I create the view object that uses the store:
var view = {xtype: 'myview'};
Idea 2:
Maybe I could dynamically switch out the url from the proxy and have separate JSON files for each id (there won't be too many). But that seems unlikely to work.
Idea 3:
Pass in a data object to the store (again parsing the JSON) from that controller.
Are any of these feasible? And if not, what is an alternative solution?Perhaps I'm overthinking this.
Edit:
I have a list of items, and each item has a list of sub-items. So when I select one item, I want to be taken to page of the sub-items. Right now, all of these sub-items are in one JSON file, so after clicking on one item, I need a way of telling the store to load only part of the json data.
Is Ext.data.model.load still the best approach?
Idea 1:
Yes, you could do that... probably more trouble than it's worth IMO. The store will load immediately after it is created -- so if you create the store at application start, then it loads then. If you create a store randomly during runtime, it loads then. If the store is defined inline for a view, it's loaded when the view is created.
Idea 2:
Arguably a better solution, but still a lot of trouble to swap the URL for the proxy, then forcibly load it, parse the data, etc.
Depending on your view, you could just directly load the data for a single model using NativeApp.model.Item.load(id) (see docs). This assumes you have an API setup for that, but it's easier IMO and certainly more RESTful.
Idea 3:
Meh. It really sounds to me like Ext.data.Store is the wrong construct for what you're trying to accomplish.
Are any of your ideas feasible? Yes.
Are you over-thinking this? Slightly, but then again you wouldn't be a programmer if you didn't.
It's hard to tell you exactly what I'd do without seeing the rest of your application and understanding the WHY you're doing X, Y, or Z... but if you're only planning on displaying a single model's data on a given "Detail" screen (and you need that data loaded on-demand), then the static Ext.data.Model.load() method is probably what you need.
I'm new to Extjs4.2/OL/Geoext2 developing, and I'm confused about how it should work.
--- edit ---
I'm trying to write a small app to read GeoJSON, place read features on the map, let the user to edit them / draw new ones, and finally save them back to GeoJSON.
My current approach:
OpenLayers.Layer.Vector is bound to Geoext.data.FeatureStore.
Layer reads GeoJSON, and FeatureStore is populated.
And now my question - how to save the modified by user data to GeoJSON?
I can save the data as JSON by FeatureStore, but I don't see an easy way to make FetureStore save GeoJSON. Should I use vector layer to save GeoJSON, or try to add some type of conversion to add geometry attributes of the features to FeatureStore, and then sync() the store?
--- edit ---
Already done this by inserting another attribute to the model:
{
name: 'geom',
convert: function(value, record) {
return record.raw.geometry.toString();
}
}
Now my FeatureStore saves GeoJSON-like output with geometry, which is ok for me.
Question: Is it the right way to do this?
Regards, Pawel
I'm not an expert, but I think GeoExt.data.FeatureStore was created to be synchronized with the layer. So, if you do a store.sync() no update request will be sent to your remote GeoJSON data source. GeoExt.data.FeatureStore constructor starts by creating a proxy: { type: 'memory', ... and thus your original proxy will be replaced by this one. To use the GeoExt.data.FeatureStore you have to rewrite it.
So, I think the best way to do this is to use a OpenLayers.Protocol.Script source, which is quite flexible, configured to use your remote GeoJSON source. Using the layer's save strategy, all updates will be sent to the remote source.
Regards!
I'm using a store to fetch the specializations of all hikers (so hiker has many specializations). However, I have a detail window where this specializations are added/removed/shown ony for currently selected hiker (yea, it's a detail window).
My problem here is that my store fetch data for all hikers, but I want it to show, when detailed window is up, only data for given hiker. Notice also that I'm showing data in data-grid, so the user possibly can add filters and I noticed that if I add a filter with store.filter({...}) and user add a filter with data-grid, my filters are removed (so basically they are useless.
Which approach should I use? Do you have any suggestion? I were thinking about 1 store for each hiker, but I don't like this solution.
Edit 1:
I also noticed that I can't create a filter in the same way as data-grid builds them:
Ext.create('Ext.util.Filter', {
type: 'numeric',
comparison: 'eq',
field: 'hiker_id',
property: 'hiker_id',
value: me.hiker.get('id'),
root: 'data'
})
Which is boring, because I imnplemented on server side a functionality that parses the grid filters already.
We just give our filters in json format to the store's extra params. And parse that back-end. The extra params stay the same while paging or refreshing the grid.
grid.getStore().getProxy().extraParams = { filter: yourFilter };
-How- are your users doing the filter?
store.filter accepts both arrays and functions, so you can do quite a bit with it, without actually juggling the data on the server. (eg manage an array that is being passed to the filter, test against an object somewhere, or whatever)
Permanent filter? Not so much, but since you can add multiple filters etc, it is relatively trivial to keep track of what filters are in place.
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.Store-method-filter
I have a combo field with queryMode: 'remote' and the store has a structure similar to this:
{
success: true,
data: [
{'name':'john','value':1},
{'name':'mary','value':2}
]
}
How can I remove the first element of the data array if I want to, before it is loaded into the combo list?
I tried capturing the load event and splicing the data array but I didn't seem successful.
A solution in the context of the one posted in this thread would really be helpful.
First of all, removing the first element in the UI is questionable, if you ever decide to expose your services through web services, that logic of removing the first element won't be there.
That being said I think you can listen to the load event and do store.removeAt(0)
override getData of reader in store.