I'm trying to make a combobox that dependent from other combobox with default values but into the listeners of combobox must loading data of itself . I have the problem when using this.store.loadData(todoItems) with todoItems as an array of four positions.
This's store:
var cmb_items = new Ext.data.SimpleStore({
fields : ['itemId', 'item'],
data : itemsMenu
});
I dont know why. Here is my code, can anyone lend me a hand?
{
xtype : 'combo',
store : cmb_items,
hiddenName : 'id_item',
valueField : 'id_item',
mode : 'local',
allowBlank : false,
value : nombreItem,
fieldLabel : 'items',
disabled : true,
name : 'items',
triggerAction : 'all',
emptyText : 'Seleccione un item',
editable : false,
id : "items",
anchor : '90%',
displayField : 'item',
listeners : {
select: function () {
idSistema = Ext.getCmp("sistemas").getValue();
selectedMenu = Ext.getCmp("menus").getValue();
todoItems = getItemsMenu(selectedMenu,idSistema);
//alert(todoItems)
this.store.loadData(todoItems);
idItem = this.getValue();
alert(idItem); // RETURN UNDEFINED
for(i=0;i<this.store.getCount();i++){
if(todoItems[i][0]==idItem){
nombreItem = todoItems[i][1];
outItem = todoItems[i][2];
}
}
}
}
},
Thank you!
I'm not much clear with code, but if you're looking for combo depends another means, try my example.
var countryStore = new Ext.data.SimpleStore({
fields: ['alpha2code','name'],
data: [["BE","Belgium"],["BR","Brazil"],["BG","Bulgaria"]]
});
function getState(stCode){
var data=[];
switch(stCode){
case 'BE':
data=[["BE","Belgium1"],["BR","Brazil1"],["BG","Bulgaria1"]];
break;
case 'BR':
data=[["BE","Belgium2"],["BR","Brazil2"],["BG","Bulgaria2"]];
break;
case 'BG':
data=[["BE","Belgium3"],["BR","Brazil3"],["BG","Bulgaria3"]];
break;
}
return data;
};
var statesStore = new Ext.data.SimpleStore( {
fields: ['statecode','name']
});
var stateForm = new Ext.form.ComboBox({
fieldLabel : 'Country',
id : 'countryCombo',
name : 'country',
msgTarget : 'side',
triggerAction : 'all',
lazyRender : true,
store : countryStore,
mode: 'local',
valueField : 'alpha2code',
emptyText : 'Create or Select an partment',
displayField : 'name',
editable : true,
listeners:{
'select': function(combo,value,index){
debugger;
var input = combo.getValue();
var stateCombo=Ext.getCmp('statesCombo');
//stateCombo.clearValue();
//stateCombo.store.baseParams.countryID=input;
stateCombo.store.loadData(getState(input));
}
}
});
var stateForm1 = new Ext.form.ComboBox({
fieldLabel : 'States',
id : 'statesCombo',
name : 'states',
mode: 'local',
msgTarget : 'side',
triggerAction : 'all',
lazyRender : true,
store : statesStore,
valueField : 'statecode',
emptyText : 'Create or Select an Department',
displayField : 'name',
editable : true
});
var formPanel = new Ext.form.FormPanel({
title: 'World',
labelWidth: 120,
width: 350,
padding: 10,
items:[stateForm,stateForm1]
});
formPanel.render(document.body);
Related
It is actually a external window, the first time click open the window, the combobox are contain the value but the second and third times is no longer anymore. May i knw how to reload my combobox?
Tried few ways to reload the combobox, but failed, please gv me some idea.
Below is my code.
ViewUserRole = Ext.extend(One.Report, {
reportName : '.ViewUserRoles',
customModelName : 'Standard Role',
autoExecute: true,
isDetailPage: false,
listeners: {
bbarconfig: function(report, bbarConfig) {
bbarConfig.items.push({
xtype: 'button',
text: 'Create New Role',
disabled: false,
listeners: {
click : function(btn, e) {
var w = new .CreateNewUserRole();
w.show();
}
}
});
}
}
});
One.PageMgr.regDetail('Role', '.ViewUserRole');
// To call new Create User Role Form
CreateNewUserRole = new Ext.extend(Ext.Window,{
id:'CreateNewUserRole',
height :250,
minHeight: 220,
width:550,
minWidth: 500,
modal:true,
title: Form_NewRole,
layout: 'form',
plain: true,
initComponent: function() {
this.items = [new .CreateUserRoleForm()];
.CreateNewUserRole.superclass.initComponent.apply(this, arguments);
},
bodyStyle: 'padding:5px;',
buttonAlign: 'center',
buttons: [{
text: Button_ReadMe,
listeners: {
click : function(btn, e) {
Ext.MessageBox.show({
title: Header_Information,
msg: Msg_CreateUserRoleNameExplain,
buttons: Ext.MessageBox.OK,
icon: Ext.MessageBox.INFO
});
}
}
},{
text: Button_Save,
handler:function(){
Ext.Ajax.request({
url: '/oms/rest/manageuserrole/addnewrole',
params: {
enterpriseId: enterpriseId, organizationId: organizationId
},
method: 'GET',
success: function() {
Ext.Msg.alert(Msg_SuccessfullyCreatedUserRole);
Ext.getCmp('CreateNewUserRole').close();
},
failure: function(response, opts) {
Ext.MessageBox.show({
title: Header_Error,
msg: 'Server-side failure with status code ' + response.status,
buttons: Ext.MessageBox.OK,
icon: Ext.MessageBox.ERROR
});
},
scope: this
});
}
},{
text: Button_Cancel,
handler:function(){
Ext.getCmp('CreateNewUserRole').close();
}
}]
});
// Get All Enterprise List from Database
var enterpriseListStore = new Ext.data.JsonStore({
autoLoad: true,
url: '/oms/rest/getEntOrgList/getEnterpriseList',
root : 'enterprise',
fields :[{name: "enterpriseID", type: "int"},{name: "enterpriseName", type: "string"}]
});
//Get All Organization List from Database
var organizationListStore = new Ext.data.JsonStore({
autoLoad: true,
url: '/oms/rest/getEntOrgList/getOrganizationList',
root : 'organization',
fields :[{name: "organizationID", type: "int"},{name: "organizationName", type: "string"}]
});
// Create User Role Design
CreateUserRoleForm = Ext.extend(Ext.form.FormPanel, {
initComponent : function() {
this.items = [{
xtype : 'combo',
id : 'EnterpriseSel',
fieldLabel : Field_Enterprise,
name : 'enterprise',
displayField : 'enterpriseName',
valueField : 'enterpriseID',
baseCls : 'fwd_floatLeft',
anchor : '75%',
queryMode : 'local',
mode : 'local',
editable : false,
triggerAction : 'all',
listClass : 'comboalign',
typeAhead : true,
labelWidth : 50,
hiddenName : 'number',
selectOnFocus : true,
store : new Ext.data.JsonStore({
storeId : 'enterpriseListStoreId',
autoLoad : false,
url : '/oms/rest/getEntOrgSiteList/getEnterpriseList',
root : 'enterprise',
fields :[{name: "enterpriseID", type: "int"},{name: "enterpriseName", type: "string"}]
}),
listeners : {
change: function(field, newValue, oldValue){
organizationListStore.load();
}
}
},{
xtype : 'combo',
id : 'OrganizationSel',
fieldLabel : Field_Organization,
name : 'organization',
displayField : 'organizationName',
valueField : 'organizationID',
baseCls : 'fwd_floatLeft',
anchor : '75%',
queryMode : 'local',
mode : 'local',
editable : false,
triggerAction : 'all',
listClass : 'comboalign',
typeAhead : true,
labelWidth : 50,
hiddenName : 'number',
selectOnFocus : true,
store : organizationListStore
}];
CreateUserRoleForm.superclass.initComponent.apply(this, arguments);
}
});
First of all,
CreateNewUserRole = new Ext.extend(Ext.Window,{
should be changed to
CreateNewUserRole = Ext.extend(Ext.Window,{
And where is the definition of Combobox to see if there is any problem with it? It can be possible that you have specified static "id" to the combobox in CreateUserRoleForm.
You can define your stores with a storeId -
var enterpriseListStore = new Ext.data.JsonStore({
autoLoad: true,
storeId : "enterprise-lists",
url: '/oms/rest/getEntOrgList/getEnterpriseList',
root : 'enterprise',
fields :[{name: "enterpriseID", type: "int"},{name: "enterpriseName", type: "string"}]
});
var organizationListStore = new Ext.data.JsonStore({
autoLoad: true,
storeId : "organization-lists",
url: '/oms/rest/getEntOrgList/getOrganizationList',
root : 'organization',
fields :[{name: "organizationID", type: "int"},{name: "organizationName", type: "string"}]
});
so that they won't be destroyed even when the windows are closed.
I'm new with ExtJS.
I have two grids on a same page. First grid has 3 columns. Second only one. Problem is that when second is rendered, it is overwriting properties of the first grid.
For example when I try to edit row in first grid, it takes the width on the row from second grid.
var $booleanArray = [
['denied', 'Denied'],
['allowed', 'Allowed']
];
var myPageSize = 10;
Ext.Loader.setConfig({ enabled: true });
Ext.require([
'Ext.grid.*',
'Ext.data.*',
'Ext.util.*',
'Ext.state.*'
]);
Ext.onReady(function () {
Ext.define('CharacteristicModel', {
extend: 'Ext.data.Model',
fields: [ {name: 'name'}, {name: 'value'}, {name: 'order'} ],
validations: [
{
type : 'length',
field: 'name',
min : 1
}
]
});
var characteristicsStore = new Ext.data.Store({
proxy : {
model : 'CharacteristicModel',
type : 'rest',
api : {
read : admin_path + '/getCharacteristics/1/',
create : admin_path + '/saveCharacteristics/1/',
update : admin_path + '/saveCharacteristics/1/',
destroy: admin_path + '/destroyCharacteristic/1/'
},
reader : {
type : 'json',
root : 'data',
totalProperty: 'total_count'
},
writer : {
type: 'json',
root: 'data'
},
buffered: true
},
listeners: {
read : function (response) {
},
load : function (store) {
},
write: function (store, operation) {
store.load();
}
},
pageSize : myPageSize,
autoLoad : { start: 0, limit: myPageSize },
autoSync : true
});
var rowEditing = Ext.create('Ext.grid.plugin.RowEditing');
var characteristicsGrid = new Ext.grid.GridPanel({
id : 'characteristicsGrid',
renderTo : 'characteristics_grid_div_1',
store : characteristicsStore,
width : 480,
stateful : true,
stateId : 'characteristicsGrid',
title : 'Grid "1"',
iconCls : 'icon-user',
listeners : {
itemdblclick: function (dv, row, item, index, e) {
dv.refresh();
dv.getGridColumns()[0].setEditor({
disabled: true,
editable: false
});
if (row.data.id == 6 || row.data.id == 7) {
dv.getGridColumns()[1].setEditor({
xtype : 'combo',
store : new Ext.data.ArrayStore({
fields: ['abbr', 'action'],
data : $booleanArray
}),
displayField : 'action',
valueField : 'abbr',
mode : 'local',
typeAhead : false,
triggerAction: 'all',
lazyRender : true,
emptyText : 'Select action'
});
}
else if (row.data.id == 8 || row.data.id == 11) {
dv.getGridColumns()[1].setEditor({
disabled: true,
editable: false
});
}
else {
dv.getGridColumns()[1].setEditor({
xtype: 'textfield'
});
}
}
},
columns : [
{
id : 'name',
text : 'Account characteristic',
sortable : false,
width : 340,
fixed : true,
dataIndex: 'name'
},
{
id : 'value',
text : 'Value',
sortable : false,
dataIndex: 'value',
width : 70,
fixed : true,
editor : {
xtype: 'textfield'
},
renderer : function (value, field) {
if (field.record.data.id == 6 || field.record.data.id == 7) {
if ($booleanArray[0][0] != value) {
value = $booleanArray[1][1];
}
else {
value = $booleanArray[0][1];
}
}
return value;
}
},
{
id : 'order',
text : 'Order',
sortable : false,
dataIndex: 'order',
width : 70,
fixed : true,
editor : {
xtype: 'textfield'
},
renderer : function (value, field) {
return value;
}
}
],
bbar : Ext.create('Ext.PagingToolbar', {
store : characteristicsStore,
displayInfo: true,
pageSize : myPageSize,
displayMsg : 'Show {0} - {1} из {2}',
emptyMsg : "0 rows"
}),
dockedItems: [
{
xtype: 'toolbar',
items: [
{
text : 'Add',
iconCls: 'icon-add',
handler: function () {
var grid_colums = rowEditing.cmp.getSelectionModel().view.getGridColumns();
grid_colums[0].setEditor({
xtype : 'combo',
store : new Ext.data.ArrayStore({
fields: ['id', 'name'],
data : $characteristics
}),
displayField : 'name',
valueField : 'id',
mode : 'local',
typeAhead : false,
triggerAction: 'all',
lazyRender : true,
emptyText : 'Select action'
});
grid_colums[1].setEditor({
xtype: 'textfield'
});
// empty record
//characteristicsStore.autoSync = false;
characteristicsStore.insert(0, new CharacteristicModel());
rowEditing.startEdit(0, 0);
//characteristicsStore.autoSync = true;
}
},
'-',
{
itemId : 'delete',
text : 'Delete',
iconCls : 'icon-delete',
disabled: true,
handler : function () {
var selection = characteristicsGrid.getView().getSelectionModel().getSelection()[0];
if (selection) {
characteristicsStore.remove(selection);
}
}
}
]
}
],
plugins : [rowEditing]
});
characteristicsGrid.getSelectionModel().on('selectionchange', function (selModel, selections) {
characteristicsGrid.down('#delete').setDisabled(selections.length === 0);
});
});
Ext.onReady(function () {
Ext.define('AdvantagesModel', {
extend: 'Ext.data.Model',
fields: [
{name: 'name'}
]
});
// setup the state provider, all state information will be saved to a cookie
//Ext.state.Manager.setProvider(Ext.create('Ext.state.CookieProvider'));
var advantagesStore = new Ext.data.Store({
idProperty: 'AdvantagesModel',
proxy : {
model : 'AdvantagesModel',
type : 'rest',
api : {
read : admin_path + '/getAdvantages/1/',
create : admin_path + '/saveAdvantages/1/',
destroy: admin_path + '/destroyAdvantages/1/'
},
reader : {
type : 'json',
root : 'data',
totalProperty: 'totalCount'
},
writer : {
type: 'json',
root: 'data'
},
buffered: true
},
listeners: {
read : function (response) {
},
load : function (store) {
},
write: function (store, operation) {
store.load();
}
},
pageSize : myPageSize,
autoLoad : { start: 0, limit: myPageSize },
autoSync : true
});
var rowEditing = Ext.create('Ext.grid.plugin.RowEditing');
var advantagesGrid = new Ext.grid.GridPanel({
id : 'advantagesGrid',
renderTo : 'advantages_grid_div_1',
store : advantagesStore,
width : 482,
height : 355,
stateful : true,
stateId : 'advantagesGrid',
title : 'Grid 2',
iconCls : 'icon-user',
listeners : {
beforeedit: function (dv, row, item) {
//advantagesGrid.getView().refresh();
if (row.record.raw)
{
return false;
}
}
},
columns : [
{
id : 'name',
text : 'Advantages',
sortable : false,
dataIndex: 'name',
width : 480
}
],
bbar : Ext.create('Ext.PagingToolbar', {
store : advantagesStore,
displayInfo: true,
pageSize : myPageSize,
displayMsg : 'Show {0} - {1} из {2}',
emptyMsg : "0 rows"
}),
dockedItems: [
{
xtype: 'toolbar',
items: [
{
text : 'Add',
iconCls: 'icon-add',
handler: function () {
var grid_colums = rowEditing.cmp.getSelectionModel().view.getGridColumns();
grid_colums[0].setEditor({
xtype : 'combo',
store : new Ext.data.ArrayStore({
fields: ['id', 'name'],
data : $advantages
}),
displayField : 'name',
valueField : 'id',
mode : 'local',
typeAhead : false,
triggerAction: 'all',
lazyRender : true,
emptyText : 'Select action'
});
// empty record
advantagesStore.autoSync = false;
advantagesStore.insert(0, new AdvantagesModel());
rowEditing.startEdit(0, 0);
advantagesStore.autoSync = true;
}
},
'-',
{
itemId : 'delete',
text : 'Delete',
iconCls : 'icon-delete',
disabled: true,
handler : function () {
var selection = advantagesGrid.getView().getSelectionModel().getSelection()[0];
if (selection) {
advantagesStore.remove(selection);
}
}
}
]
}
],
plugins : [rowEditing]
});
advantagesGrid.getSelectionModel().on('selectionchange', function (selModel, selections) {
advantagesGrid.down('#delete').setDisabled(selections.length === 0);
});
});
The alternative to having your two grid id columns identified differently is to have two different instances/objects of the Ext.grid.plugin.RowEditing class if you have two editable grids on the same page. Many times it's important to have the same id.
var rowEditing = Ext.create('Ext.grid.plugin.RowEditing');
var rowEditing2 = Ext.create('Ext.grid.plugin.RowEditing');
plugins : [rowEditing]
plugins : [rowEditing2]
found the problem.
columns : [
{
id : 'name',
columns ids must be different, even if they are in diferent grids
I want a grid that will change or reload after delete any row and retrieve those rows that have same member id. For this, I add filter. Again I callback store with filter after delete any row. My store filter well but grid couldn't display it......It holds the previous display......
Ext.define('${pkgName}.v02x001001.SV02X00100101' , {
extend : 'Ext.grid.Panel',
alias : 'widget.sv02x00100101',
id : 'sv02x00100101',
border : true,
modal : true,
height : 300,
width : 455,
viewConfig: {
stripeRows : true,
forceFit : true,
emptyText : 'No Records to display',
listeners : {
viewready : function(v) {
var store = Ext.data.StoreManager.get('S02X001001');
store = !store ? Ext.create("S02X001001") : store;
var value = Ext.getCmp('member-sv02x00100104').getValue(),
filters = new Array();
store.clearFilter();
store.filter('member', value);
filters.push({
property : 'member',
value : value
});
store.loadPage(1, {
filters : filters
});
}
}
},
initComponent: function() {
this.store = 'S02X001001';
this.tbar= Ext.create('Ext.ux.StatusBar', {
topBorder : false,
statusAlign : 'right',
items : [{
xtype :'button',
text : 'ADD',
icon : "${resource(dir: 'images', file: 'ADD01003.png')}",
listeners : {
click : this.onNewAddress
}
},'-']
});
this.columns = [
{
text : 'Address Line 1',
dataIndex : 'addressline1',
sortable : false,
flex : 1
},{
text : 'Address Line 2',
dataIndex : 'addressline2',
sortable : false,
width : 170
},{
menuDisabled : true,
sortable : false,
id : 'deletee',
xtype : 'actioncolumn',
width : 22,
items : [{
icon : "${resource(dir: 'images', file: 'DEL01005.png')}",
tooltip : 'Delete This?',
scope : this,
handler : function(grid, rowIdx, colIdx) {
var record = grid.getStore().getAt(rowIdx);
var conId = record.data.id
this.onDeleteClick(conId);
}
}]
}];
this.callParent(arguments);
},
onNewAddress: function(btn, e, eOpts){
var view=Ext.widget('sv02x00100102');
view.show();
var a = Ext.getCmp('member-sv02x00100104').getValue();
Ext.getCmp('member-sv02x00100102').setValue(a);
},
onDeleteClick:function(conId){
Ext.MessageBox.show({
title : 'Delete',
msg : 'Really want to delete ?',
icon : Ext.Msg.WARNING,
buttons : Ext.MessageBox.YESNO,
buttonText :{
yes: "Delete",
no : "No"
},
scope : this,
animateTarget : 'deletee',
fn: function(btn, dbQty){
if(btn == 'yes'){
var registration = Ext.create('${appName}.model.M02X001001',{
id : conId
});
var store = this.getStore();
registration.destroy({
scope : this,
success : function(model, operation) {
if(model != null){
var store = Ext.data.StoreManager.get('S02X001001');
store = !store ? Ext.create("S02X001001") : store;
var value = Ext.getCmp('member-sv02x00100104').getValue(),
filters = new Array();
store.clearFilter();
store.filter('member', value);
filters.push({
property : 'member',
value : value
});
store.loadPage(1, {
filters : filters
});
}
},
failure: function(){
console.log('Unable to delete');
}
});
}
}
});
}
});
How it possible to retrieve rest of the relative rows ........
Here is my Store ..........
Ext.define('${pkgName}.S02X001001', {
extend : 'Ext.data.Store',
model : '${appName}.model.M02X001001',
idProperty: 'id',
autoLoad : true,
autoSync : true,
filterParam: 'query',
remoteSort: true,
proxy : {
type : 'ajax',
noCache : false,
limitParam: 'limit',
startParam: 'start',
url : '${createLink(controller:'C02x001001', action: 'store')}',
reader:{
type : 'json',
root : 'data',
totalProperty : 'total',
successProperty : 'success',
messageProperty : 'message',
implicitIncludes: true
},
simpleSortMode : true
},
sorters: [{
property: 'id',
direction: 'asc'
}]
});
it should be refresh the grid view in automatic,
but you can refresh the view by manual way :
use method getView().refresh();
try:
Ext.getCmp('sv02x00100101').getView().refresh();
I am new to ext js. And my requirement is OnClick of a button, it calls a js function which pops up a window.Within this window I have a formPanel and a grid embedded in it. In the window items properties, if I add grid, the window is not showing. If I keep only form variable, then the window is displayed.
items : [filterPIDForm,pidGrid] is not working whereas
items: [filterPIDForm] is working fine.
Below is the code snippet
<script type="text/javascript">
jQuery(document).ready(function(){
// eCube search
jQuery('#eCubeSearch').click(function(){
pidSearch();
});
});
function pidSearch()
{
var filterPIDForm = new Ext.form.FormPanel({
title : 'Job Filters',
floatable : false,
id : 'filterForm',
tabTip : 'woot',
labelAlign :'top',
region :'west',
collapsible : true,
bodyStyle : 'padding: 5px; background-color: #DFE8F6',
border : false,
// style : 'border-top: 1px solid #99BBE8;',
width : 220,
items : [
{
xtype : 'combo',
width : 200,
id :'emailCombo',
fieldLabel :'Filter by Owner',
valueField :'emailValue',
displayField :'emailDisplay',
mode :'local',
editable :false,
typeAhead :false,
triggerAction :'all'
},
{
xtype : 'combo',
width : 200,
id :'statusCombo',
fieldLabel :'Filter by Status',
valueField :'statusValue',
displayField :'statusDisplay',
mode :'local',
editable :false,
typeAhead :false,
triggerAction :'all'
//value :'ALL'
},
{
xtype : 'textfield',
fieldLabel : 'PID/Description Search',
width : 200,
id :'searchText'
}
],
buttons: [
{
text : 'Clear Filter(s)',
id : 'clear'
},
{
text : 'Apply Filter(s)',
id : 'apply'
}
]
});
var pidGrid = new Ext.grid.GridPanel({
title : 'Job List',
id : 'pidList',
columns: [
//new Ext.grid.RowNumberer(),
{
header : 'PID',
width : 70,
dataIndex : 'pid',
sortable : true
},
{
header : 'Description',
id : 'description',
dataIndex : 'description',
sortable : true
}
]
});
var win = new Ext.Window({
modal:true,
title: 'PID Search',
layout:'absolute',
id: 'eCubeSearchWin',
width:1000,
height:400,
resizable: false,
plain: false,
resizable: false,
border: true,
closeAction :'close',
items : [filterPIDForm,pidGrid],
//items : [filterPIDForm],
buttons : [
{
text : 'OK',
id : 'test'
},
{
text : 'Close',
handler : function(){
Ext.getCmp('eCubeSearchWin').close();
}
}
]
});
win.show();
}
</script>
try setting layout in window
var win = new Ext.Window({
renderTo : Ext.getBody(),
width : 500,
height : 500,
layout : 'border',
items : [{
items : filterPIDForm
,layout :'fit'
,region : 'north'
,height : 300
},{
items : pidGrid
,layout :'fit'
,region :'center'
}]
}).show();
I would like to insert a new node into my Tree.
I develop with Sencha library version 4.
TreeNode seems not working ... Firebug error :
Erreur : uncaught exception: Ext.Loader is not enabled, so dependencies cannot be resolved dynamically. Missing required class: Ext.tree.TreeNode
I have add Loader config enable : true . it don't work too ... !
My code :
/*Ext.Loader.setConfig({
enabled: true
});
*/
Ext.require([
'Ext.form.*',
'Ext.grid.*',
'Ext.tree.*',
'Ext.data.*',
'Ext.util.*',
'Ext.loader.*',
'Ext.state.*',
'Ext.layout.container.Column',
'Ext.tab.TabPanel'
]);
Ext.onReady(function(){
Ext.QuickTips.init();
Ext.define('Task', {
extend : 'Ext.data.Model',
fields : [
{ name : 'id', type :'int'},
{ name : 'task', type : 'string' },
{ name : 'material', type : 'string'},
{name : 'cc' , type : 'string'},
{ name : 'date_debut', type : 'string'}
]
});
var store = Ext.create('Ext.data.TreeStore',{
model : 'Task',
proxy : {
type : 'ajax',
url : 'myjson.json'
},
folderSort: true
});
var tree = Ext.create('Ext.tree.TreePanel',{
title : 'Task Manager',
width :1000,
height : 400,
//renderTo : Ext.getBody(),
collapsible : true,
useArrows : true,
rootVisible : false,
store : store,
multiSelect : true,
itemId : 'id',
singleExpand : true,
tbar : [
{
xtype : 'button' , text : 'ADD TASK ',
handler : function(){
var selectedItem = tree.getSelectionModel().getSelection();
if(!selectedItem){
selectedItem = tree.getRootNode();
}
handleCreate = function(btn, text,cBoxes){
if(btn=='ok' && text){
//alert('oui');
//var newNode = new Ext.tree.TreeNode({});
var newNode = Ext.create('Ext.tree.TreeNode',{
id : '0',
task : text,
material : 'New Material',
cc : 'new CC',
date_debut :'00/00/00',
leaf : false,
allowChildren : false
});
if(selectedItem.isLeaf()) {
selectedItem.parentNode.insertBefore(newNode, selectedItem.nextSibling);
} else {
selectedItem.insertBefore(newNode, selectedItem.firstChild);
}
}else{
alert('non');
}
}
Ext.MessageBox.show({
title:'Add new Folder Item',
msg: 'Name of Folder Item:',
buttons: Ext.MessageBox.OKCANCEL,
prompt:true,
fn: handleCreate
});
}
}
],
listeners : {
itemclick : function(a,b,c,d,e){
var size = b.length;
// alert(d + ' ' + b.toString()+' b size = '+size+' e ' + e + ' a ' + a);
if( b instanceof Task){
// Form = les champs dans le form editable
var form = fields.getForm();
//Chaque field de la zone d'edition
var fId = form.findField('id');
var ftask = form.findField('task');
var fmaterial = form.findField('material');
var fcc = form.findField('cc');
var fStartDate = form.findField('start_date');
fId.setValue(b.get('id'));
ftask.setValue(b.get('task'));
fmaterial.setValue(b.get('material'));
}
}
},
//plugins: [cellEditing],
columns : [{
text : 'ID',
dataIndex : 'id',
sortable : true,
width : 50
},{
xtype : 'treecolumn',
text : 'Task',
flex : 2,
sortable : true,
dataIndex : 'task',
width : 100
},
{
text : 'Material',
dataIndex : 'material',
width : 100
},
{
text : 'CC',
dataIndex : 'cc',
width : 100
},
{
text : 'Date_Debut',
dataIndex : 'date_debut',
width : 100
}]
});
var states = Ext.create('Ext.data.Store', {
fields: ['abbr', 'name'],
data : [
{"abbr":"AL", "name":"Alabama"},
{"abbr":"AK", "name":"Alaska"},
{"abbr":"AZ", "name":"Arizona"}
]
});
var fields = Ext.create('Ext.form.Panel',{
frame : true,
title : 'Editing Zone',
width : 1000,
fieldDefaults : {
msgTarget : 'side',
labelWidth : 75
},
defaultType : 'textfield',
defaults : {
anchor : '100%'
},
items : [
//TaskName
{
fieldLabel : 'TaskName',
name : 'task',
allowBlank : false
},{
xtype: 'combo',
name : 'material',
fieldLabel: 'Choose Material',
store: states,
queryMode: 'local',
displayField: 'name',
valueField: 'abbr'
},{
xtype:'datefield',
anchor : '100%',
disabledDays: [0, 6],
fieldLabel : 'date_debut'
},{
xtype : 'hiddenfield',
name : 'id'
}],
layout: 'hbox',
buttons: [{
text: 'Reset',
handler: function() {
this.up('form').getForm().reset();
}
}, {
text: 'Submit',
formBind: true, //only enabled once the form is valid
handler: function() {
var id =this.up('form').getForm().findField('id');
var id2 = id.getValue();
var node = tree.getSelectionModel().getSelection();
alert(node);
}
}],
});
fields.render('mesfields');
tree.render('mongrid');
});
I assume that this was originally 3.x code that you are converting to 4.0? The TreeNode class no longer exists in 4.0. Instead you would create a standard Model instance and append that to your tree. In 4.0 the tree's model (what were records in 3.x) get "decorated" with the new NodeInterface class, meaning that your model objects will also have a node API when they are used in the tree. I.e., no need for a TreeNode object separate from the Model itself.
Hi I'd had a similar problem and looking in the doc found:
Ext.data.NodeInterface, is a node from the treePanel in my case I get the root node and add a child by the method apendChild
Ext.Ajax.request({
loadMask: true,
url: 'index.php?X=1',
success: function (resp) {
var t = Ext.decode(resp.responseText);
root = Ext.getCmp('tree-panel').getRootNode(); //get the root node
for (i = 0; i < t.length; i++) {
root.appendChild({
id: i,
text: t[i],
leaf: true
}); //add childs
}
Ext.get(document.body).unmask();
}
});
I can see its easer. NodeInterface has other more usefull methods :)
not sure with the error, cause i did not test your code...
but from this forum, i got conclusion that Ext.require is include a script from file system...
like
Ext.require([
'Ext.form.*',
'Ext.tree.*',
]);
it's mean include all js in src/form/ and src/tree/ more info
the error what you get is because var newNode = Ext.create('Ext.tree.TreeNode',{
and there is not a TreeNode.js in C:\xampp\htdocs\ext-4b3\src\tree (my local).