I am creating a custom plugin where I need to list some stuff in the backend area. Each item in the list has the option to open a detail window where I want to display some info and a SELECT OPTION field but not sure how to create it. That field is just to select the option you want and save it in the database.
Is it possible to create it in myplugin/Resources/views/backend/my_plugin/model/product.js file?
I have something like this (sample):
Ext.define('Shopware.apps.MyPlugin.model.Product', {
extend: 'Shopware.data.Model',
configure: function() {
return {
controller: 'MyPlugin',
detail: 'Shopware.apps.MyPlugin.view.detail.Product'
};
},
fields: [
{ name : 'id', type: 'int', useNull: true },
{ name : 'Name', type: 'string' },
{ name : 'Lastname', type: 'string' },
{ name : 'Date', type: 'date' },
{ name : 'Color', type: 'SELECT?' }
]
});
Of course the Color field doesnt recognize the SELECT there but I was wondering if there's another word for it?
I was hoping to create that new field like this:
fields: [
...
{
name : 'Color',
type: 'SELECT?',
values: {'green', 'blue', 'red'}
}
]
If I am completly wrong could you please guide me where to create this field?
Thanks in advance.
You're defining a model, not a plugin and it looks like you want to configure 'Color' as an enum? Am I right?
The standard types are:
Ext.data.field.Field //(Default, implies no conversion)
Ext.data.field.String
Ext.data.field.Integer
Ext.data.field.Number
Ext.data.field.Boolean
Ext.data.field.Date
(see documentation under Field Types)
You can probably just use a string unless you want model validation...
You could create a custom type, extended from string or field and use a custom validator. (see same page under Validation)
Example:
Ext.define('App.field.Color', {
extend: 'Ext.data.field.Field',
alias: 'data.field.color',
// Match list of colors
validators: {
type: 'list',
list: ['green', 'blue', 'red']
}
});
Ext.define('App.model.Product', {
extend: 'Ext.data.Model',
fields: [
{ name : 'id', type: 'int', useNull: true },
{ name : 'Name', type: 'string' },
{ name : 'Lastname', type: 'string' },
{ name : 'Date', type: 'date' },
{ name : 'Color', type: 'color' }
]
});
Related
I have a grid populating records from view model (Ajax proxy data from Java restful web services). When I select a record in the grid form open and the fields are displayed. The records are editable using the form.
I have one tag field which is binded to a store and I should be able to populate the data associated to the record whenever the user selects a record.
"data" : [ {
"createdOn" : 1475678859000,
"updatedOn" : 1475679885000,
"updatedBy" : null,
"id" : 174,
"userName" : "ffff,
"firstName" : "gg",
"lastName" : "ggg",
"salesDepartment" : [ {
"id" : 3,
"code" : "FC",
"name" : "Fiat-Chrysler",
"departmentHead" : "xxx",
"applicationCode" : null} ],}
I need to bind the value of id from sales department object . how can I achieve this. Please help me.
{xtype: 'tagfield',
anchor: '100%',
reference: 'salesDept',
fieldLabel: 'Sales Dept\'s',
name: 'salesDepartment',
allowBlank: false,
displayField: 'name',
valueField: 'id',
bind: {
value: '{record.salesDepartmentIds}',
store: '{SalesDepartmentStore}'},
}
Tag fields are really only designed to work with arrays or comma separated lists;
It looks like you are trying to use with associations, which it would be nice if there was more support for this out of the box.
I've had a go, and in terms of displaying got it working however saving values will really depend on how you plan to sync values to the server, if you are going to use in built proxies etc. then this will present a whole different challenge. I would like a similar component for my own apps, I will think on this further and may even create a UX for this.
I think you have several issues here, one is getting your associations working properly, then you need to make your tagfield work as expected.
Here is the fiddle
And the key parts are:
An extended tagfield:
Ext.define('RelatedTagField', {
extend: 'Ext.form.field.Tag',
xtype: 'rtagfield',
config: {
relatedStore: null
},
setValue: function (val) {
this.setRelatedStore(val);
var value;
if (val && val.isStore) {
value = val.collect('id');
} else {
value = '';
}
this.callParent([value]);
},
getValue: function () {
return this.relatedStore;
},
onBindStore: function () {
this.callParent(arguments);
this.on('select', function (tagfield, selection) {
var selectedIds = [];
//add any new selections
Ext.each(selection, function (rec) {
var rrec = this.relatedStore.getById(rec.id);
if (!rrec) {
this.relatedStore.add(rec.data)
}
selectedIds.push(rec.id);
}, this);
//remove any not selected anymore
this.relatedStore.each(function (rrec) {
if (selectedIds.indexOf(rrec.id) == -1) {
this.relatedStore.remove(rrec);
}
}, this);
}, this);
},
})
Binding the value:
{
xtype: 'rtagfield',
fieldLabel: 'Sales Department',
name: 'id',
displayField: 'name',
valueField: 'id',
bind: {
store: '{salesDepartment}',
value: '{record.salesDepartment}'
}
},
And adding a definition for the association:
Ext.define('MyApp.model.User', {
extend: 'Ext.data.Model',
alias: 'model.user',
hasMany: [{
model: 'MyApp.model.SalesDepartmentModel',
associationKey: 'salesDepartment',
role: 'salesDepartment'
}],
requires: [
'Ext.data.field.String'
],
fields: [{
type: 'string',
name: 'userName'
}, {
type: 'string',
name: 'firstName'
}, {
type: 'string',
name: 'lastName'
}, {
name: 'salesDepartment'
}, {
name: 'roles'
}, {
type: 'string',
name: 'email'
}, {
name: 'notificationFrequencyId'
}]
});
Further reading
I suggest you read more on associations and the tagfield source code
In terms of saving records back to the server, I would recommend looking at sessions
Hello im struggling with ExtJs im Trying to change color in ExtJs grid where cell name is 'statuscode' if statuscode is 1 the cell has to change color in green! anybody an idea? Thanks
Ext.define('Shopware.apps.ArticleUpdateLog.model.ArticleUpdateLog', {
extend: 'Shopware.data.Model',
configure: function () {
return {
controller: 'ArticleUpdateLog'
};
},
fields: [
{ name : 'id', type: 'int', useNull: true },
{ name : 'importTimestamp', type: 'string' },
{ name : 'statuscode', type: 'string', useNull: true },
{ name : 'status', type: 'string', useNull: true }
]
});
Each column of a grid has a renderer config render: function(value, meta, record). So you can check with record.get('status') the current value and add a css style to the given cell.
http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.grid.column.Column-cfg-renderer
Also look at the meta paramenter which grants access to style the specific cell you want.
I have a model and its id is type string. I load a record to display in grid but the id is show 'NaN'.
json
{"results":[{"id":"FT01","name":"area1","enable":true}],"total":1,"success":true}
model
Ext.define('YX.model.Area', {
extend : 'Ext.data.Model',
fields : [
{ name : 'id', type : 'string' },
{ name : 'name', type : 'string' },
{ name : 'enable', type : 'boolean', defaultValue : true }
]
});
store
Ext.define('YX.store.AreaStore', {
extend : 'YX.store.ListStore',
model : 'YX.model.Area',
proxy : {
type : 'ajax',
url : 'area/list.do',
reader : Utils.ajax.gridReader
}
});
Utils.ajax.gridReader =
{
type : 'json',
root : 'results',
successProperty : 'success',
totalProperty : 'total'
}
If I set proxy.reader to a direct object then id is show correctly in grid.
proxy : {
type : 'ajax',
url : 'area/list.do',
reader : {
type : 'json',
root : 'results',
successProperty : 'success',
totalProperty : 'total'
}
}
That may depends on what you do with the model, and the type of storage that backs your data. In principle, there should not be such a restriction, but that may be an expectation of some part of the framework (or third-party code).
Anyway, I've written a minimal test case with your model and a grid, and the id string is displayed correctly. That means that you probably have an issue somewhere else in your code... Most probably the proxy, reader or store.
Here's the test code (running there):
Ext.define('Area', {
extend: 'Ext.data.Model',
fields: [{
name: 'id',
type: 'string'
}, {
name: 'name',
type: 'string'
}, {
name: 'enable',
type: 'boolean',
defaultValue: true
}]
});
Ext.onReady(function() {
Ext.widget('grid', {
renderTo: Ext.getBody(),
height: 300,
columns: [
{dataIndex: 'id', text: "ID"},
{dataIndex: 'name', text: "Name"}
],
store: {
model: 'Area',
proxy: {
type: 'memory'
,data: [
{id: 'foo', name: "Foo"}
,{id: 'bar', name: "Bar"}
]
},
autoLoad: true
}
});
});
this error is because of your field name is "id".
default idProperty='id' field and idProperty field must have int data.but in your case it is not.
so this code is giving you this error.
if you won't need idProperty then chanege you field's name "id" to something else
http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.data.Model-cfg-idProperty
If you want your ID to be a number, you can customize it using identifier.
This is how it worked for me. I added this code in my model:
identifier: {
type: 'sequential',
seed: 10
},
Ext.define('record.SecurityCase', {
extend : 'Ext.data.Model',
fields : [{
name : 'id',
type : 'string',
persist : false
}, {
name : 'takeplaceTime',
type : 'date',
persist : true
}, {
name : 'brief',
type : 'string',
persist : true
}],
groupField: 'takeplaceTime'
});
A grid with store used model above.And I want it to be grouped with 'takeplaceTime'.for example:
obj.takeplaceTime='2013-10-01';obj2.takeplaceTime='2013-04-01';obj3.takeplaceTime='2013-12-01';obj4.takeplaceTime='2012-12-01';
obj;obj2;obj3 are one group as its year is 2013. obj4 will be another ,year 2012.
Is there a groupRenderFunction to handle this?
You can define calculated property in Model for grouping. Example:
Ext.define('Model1', {
extend: 'Ext.data.Model',
fields: [
{name: 'name', type: 'string'},
{name: 'seniority', type: 'string'},
{name: 'department', type: 'string'},
{name: 'group', type: 'string', convert: function(value, record) {
return record.get('name').substr(0, 1); // first letter of name
} }
]
});
Working sample in Ext JS 4.2: http://jsfiddle.net/BmVeg/1/
Is there a sensible way in a model to concatenate two fields, something like this:
Ext.define('model.Person', {
extend: 'Ext.data.Model',
idProperty: 'Id',
fields: [
{ name: 'Id', type: 'int' },
{ name: 'FirstName', type: 'string' },
{ name: 'LastName', type: 'string' },
{ name: 'FullName', type: 'string', mapping: 'FirstName + " " + LastName' }
]
});
I've tried a multitude of ways, but can't seem to get any to work.
I was going to use a function in the model to stick the two fields together, but I also need to use this as the displayfield inside a 'itemselector' (custom control) and switch this dynamically and that control doesn't seem to like 'FullName()' as a displayfield.
Any thoughts greatly appreciated.
Use the convert config of the Ext.data.Field: http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.data.Field-cfg-convert
{ name: 'FirstName', type: 'string' },
{ name: 'LastName', type: 'string' },
{
name: 'FullName',
type: 'string',
convert: function( v, record ) {
return record.get( 'FirstName' ) + ' ' + record.get( 'LastName' )
}
}
Here's a live example: https://fiddle.sencha.com/#fiddle/mf