I have been continuing learning Ext JS framework.
Now I have to do next thing: load some data from server to particular form's selectfields through a REST API.
This is my proxy store:
Ext.define('Foresto.store.RESTstore',{
extend: 'Ext.data.Store',
storeID:'reststore',
proxy: {
type:'rest',
url:'http://localhost:8001/api/fieldvalues/'
},
autoLoad: true});
How should I links REST api with form's field? I have found few examples with model, but how it can be realised witout using of model? If I want use exist forms?
Thanks!
you can use fields in model.
example:
model:
fields:[
{type: 'string',name: 'CODE'}
]
view:
{
xtype:'textfield',
reference:'CODE',
name:'CODE'
}
Related
I have some client-side JSON and want to use to "quickly" experiment with various controls without writing all the REST API calls. All I want to do is point any given Kendo DataSource to the local array of data I already have instead of writing all the extra's...but nothing I do works.
I have tried various online examples...can someone direct me to something that actually works?
EXAMPLE:
This particular example is for their Donut Chart using Angular, but I cant use their data calls because of CORS & I am getting tired of writing a new set of REST calls every time I merely want to experiment with a particular control.
var data = [{ ... }, { ... }]
$scope.screenResolution = new kendo.data.DataSource({
// I dont want this at the moment
//transport: {
// read: {
// url: "http://demos.telerik.com/kendo-ui/content/dataviz/js/screen_resolution.json",
// dataType: "json"
// }
//},
sort: {
field: "order",
dir: "asc"
},
group: {
field: "year"
}
});
Datasource has a data property that you can set to a local array.
http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-data
In my Extjs project I have a model with a rest proxy defined:
Ext.define('Registration.model.Session', {
extend: 'Ext.data.Model',
fields: [
...
],
proxy:{
type: 'rest',
url: '/sessions',
reader: {
type: 'json',
rootProperty: 'records'
}
}
});
When I create a store that uses this model and try to do a GET request for a particular record id, the id is not being appended to the url for some reason:
I was reading back through the rest proxy's docs and it seems like this is all I needed to do to make a get call for a particular record.
I've not specified the appendId config in the proxy so it should be set to the default value of true.
Is there a config I'm missing on the proxy to append the id?
Nevermind. That was a goof on my part. I was calling the load method on the store and the proxy I defined is on the model.
I pulled out the model and fired it's load method with the record ID and it worked:
I should point out that I don't think this is the best way of getting this record.
So if anyone has a better suggestion I'm all ears ;)
you can also define proxies on models. I didnt realize it at first, but my team uses sencha architect and I noticed that there were the settings to connect it all up there under the model too so I tried it one day and it worked.
After I saw it in Sencha Architect, I also went back to the APIs on the site and sure enough its there too.
Did you defined idProperty: 'Id' in your model. If not try this.
I have a Kendo UI Scheduler with a timeline view in which as one of the resources, a list of Persons names are being dynamically populated in the Scheduler. To get that data, I created a remote webservice responsible to get a proper communication between the database and the front-end. When I created the web service, I also created a method called GetPersons in VB that retrieves me the data in JSON format for me to use.
resources: [{
field: "UserID",
name: "Persons",
dataTextField: "Name",
dataValueField: "Name",
dataSource: new kendo.data.DataSource({
transport: {
read: {
url: 'Service/JSON/GetPersons'
},
schema: {
type: "json",
data: "GetPersonsResult.RootResults"
}
}
),
multiple: true,
title: "name"
Now, to explain my issue:
I have a table on the database with the following fields: ID, PersonID, TypeOfEventID, startDate and endDate. In this table, I created three events just to try testing and to be related with the Persons.
I am trying to see in the Scheduler all those events I created but so far, nothing shows up. My logic was the same as with the GetPersons method. I created a new VB file called GetEvents to get me the events in the web service from the database to be retrieved and used in JSON format later. With this JSON data, I was planning to see the events I created. Just like it happend with the GetPersons method.
The view used it's a custom one based on the timelineMonth type. Every row has a different Person name and for each Person, specific events of different types might be seen.
Here's a fiddle with my script
So far, I can not see any events neither the Scheduler pop-window that shows up when I do double click inside the Scheduler.
Any tip of how to associate all these sort of things? I have no idea if I need to create another dataSource, neither I know what to put exactly on the resources and/or schema/model section.
One month after, nobody answered to my question and because of this I believe that I should post the solution:
The main thing that I had to do, was to create my second type of resources in a proper way. So, very simply... I did this:
{
field: "EventType",
dataValueField: "EventTypeID",
dataTextField: "descr",
dataColorField: "Color",
dataSource: new kendo.data.DataSource({
transport: {
read: {
url: './../Services/BlahBlahBlahDomainService.svc/JSON/GetEventType'
}
},
schema: {
type: "json",
data: "GetEventsTypeResult.RootResults",
total: "GetEventsTypeResult.TotalCount"
}
}
)
}
Besides that, I discovered some other little issues. For example:
the editable option was disabled;
both resources dataSource had no "schema.total" field defined and that options is needeed once the "schema.data" field is called;
a "dataTextField" property from one of the resources was missed;
I have a form with a combo box in it. The combo box loads it's data via a Json store and I use form.getForm().load( url: 'URL') to load the forms data also from a Json store.
When the data is loaded into the form I can see via Firebug that it receives the right value, the combo then displays the correct corresponding display value. When I look at the HTML in FireBug for the hiddenField it says the value="DISPLAYVALUE" not value="VALUE". When I then pick any value from the combo it changes to the correct value="VALUE".
Of course if the user never changes the combo the wrong value is submitted. Is this by design/limitation or am I missing something.
Do I really need to load and verify the data for each combo before I do the getForm().load()? wouldn't it make sense for load() to just load the complete data even if that means loading the data from a store?
I've included simplified sample code that has the issue.
Ext.onReady(function(){
var frmClientRecord = {
xtype: 'form',
items: [
{
fieldLabel: 'Advisor',
xtype: 'combo',
id: 'advisorName',
displayField: 'Advisor',
valueField: 'advisorId',
hiddenName: 'advisorsId',
mode: 'remote',
store: new Ext.data.Store({
autoLoad: true,
proxy: new Ext.data.HttpProxy({
url: '/referrals/index.php/advisors/read',
method: 'POST'
}),
reader: new Ext.data.JsonReader({
root: 'results',
fields: [
{name: 'advisorId'},
{name: 'Advisor'}
]
})
})
}
]
}
frmClientRecordCmp = new Ext.FormPanel(Ext.apply(frmClientRecord));
frmClientRecordCmp.getForm().load({
url: '/referrals/index.php/clients/getbyid/100',
})
frmClientRecordCmp.render(document.body);
});
JSON FOR THE COMBO
({"results":[{"Advisor":"Chris","advisorId":33},{"Advisor":"Fawzia","advisorId":2},{"Advisor":"Kent","advisorId":3},{"Advisor":"Rob","advisorId":4},{"Advisor":"Stephanie","advisorId":5}]})
JSON FOR THE FORM
{success: true, data: {"advisorsId":33}}
This could happen if your form is loading before the combo store loads. (Given that rest of your code looks Ok)
I suspect this will resolve if you render your form before loading it.
(move frmClientRecordCmp.render(document.body); one statement up in your sample code)
EDIT
Two points to consider-
Are you sure the combo store has finished loading before the form loads?
Looking at ComboBox's valueField documentation, it looks like a call to combo.setValue may be necessary after the form loads. Something along the lines of -
frmClientRecordCmp.getForm().load({
url: '/referrals/index.php/clients/getbyid/100',
success:function(form,action){
form.findField('advisorName').setValue(action.result.data.advisorId);
}
});
It was a problem I had caused by using the id: 'advisorName'. I was returning a field also named 'advisorName' so it was filling it even though I was specifying a hiddenName value. The moral is make sure your id is unique and not a field name.
I have an ExtJS combobox with a remote data store behind it. In all browsers it works fine, except in IE (all versions that I've tested) where the combobox expands for a splitsecond, showing a "loading" icon and then it disappears again. Clicking it again after this doesn't make it expand at all anymore. Basically: it's not being populated.
On the server side, everything is fine. The Controller action is reached (using ASP.NET MVC) which returns Json data. The Json is properly formed (all other browsers swallow it at least).
A weird thing is, that when I put a breakpoint in the Controller action, the JsonStore is properly filled on the client side. This to me indicates some sort of timing problem.
Another weird thing is that, every once in a while, it works fine. Perhaps because the timing is just right by accident or something.
If I set the combobox mode to 'local' and force a .load() on the remote datastore, it works fine in IE too.
This problem is present in all comboboxes that use a remote datastore for us.
I have the following JsonStore:
var companies = new Ext.data.JsonStore({
url: '/Company/GetCompanies/',
root: 'companies',
fields: [
{ name: 'CompanyID'},
{ name: 'CompanyName'}]
});
The combobox:
new Ext.form.ComboBox({
fieldLabel: 'Company',
typeAhead: false,
triggerAction: 'all',
valueField: 'CompanyID',
hiddenName: 'CompanyID',
displayField: 'CompanyName',
mode: 'remote',
lazyRender: true,
store: companies,
allowBlank: true,
editable: false,
listeners: {
'focus': function(){
if(companies.data.length > 0)
{
debugger; // This is only ever fired after the aforementioned breakpoint method.
}
}
}
})
The Json that is returned by the Controller:
{"companies":[{"CompanyID":1,"CompanyName":"Test"},{"CompanyID":2,"CompanyName":"Test1"
},{"CompanyID":3,"CompanyName":"Test2"}]}
Figures, I work out the solution just minutes after posting a question about it.
I switched to a Store instead of a JsonStore and specified the method: 'GET' property of the proxy and it worked. I have no clue why this does work though, and why only IE had a problem with it. My Controller action accepts both GET and POST so that wasn't it.
The Store:
var companies = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({ url: '/Company/GetCompanies/', method: 'GET' }),
reader: new Ext.data.JsonReader({ root: 'companies' }, [{ name: 'CompanyID', mapping: 'CompanyID' }, { name: 'CompanyName', mapping: 'CompanyName'}])
});