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
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 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 have an Extjs 4 grid with sort capability. i want to call a custum function after each time user presses sort button.
In my custom function i want to navigate to the first page of my grid (my grid uses pagination and it takes advantage of server-side sort) i think i must use store.loadPage(1) in my custom function (correct me if I'm wrong)
where should i put my custom function?
This is my Ext.OnReady() function:
Ext.onReady(function() {
Ext.tip.QuickTipManager.init();
var url = {
local: 'grid-filter.json', // static data file
remote: 'grid-filter.php'
};
var paging = true;
var encode = false;
var local = false;
Ext.define('UserDirectoryDataModel', {
extend : 'Ext.data.Model',
fields : [ 'uname', 'fname', 'lname', 'postcode', 'mail', {
name : 'pass'
}, 'hasAccess', 'isActive', 'lastVisit' , 'deleteUser'],
idProperty : 'uname'
});
var itemsPerPage = 20;
var store = Ext.create('Ext.data.Store', {
pageSize : itemsPerPage,
autoLoad: false,
local: false,
autoDestroy: true,
model : 'UserDirectoryDataModel',
autoSync : true,
sortOnLoad : true,
remoteSort:true,
sorters : {
property : 'uname',
direction : 'ASC'
},
listeners: {
beforeload: function(){
store.loadPage(1);
}
},
proxy : {
type : 'ajax',
url: (local ? url.local : url.remote),
api : {
read : 'read.php',
update : 'update.php'
},
reader : {
type : 'json',
root : 'users',
successProperty : 'success',
totalProperty : 'totalCount'
},
writer : {
type : 'json',
writeAllFields : true,
encode : false,
root : 'users'
},
afterRequest : function(request, success) {
if (request.action == 'update') {
if (success) {
Ext.MessageBox.alert('alert',
'data updated!');
}
}
}
}
});
store.load({
params:{
start:0,
limit: itemsPerPage
}
});
var filters = {
ftype: 'filters',
encode: encode, // json encode the filter query
local: local, // defaults to false (remote filtering)
filters: [
{
}
]
};
var createColumns = function (finish, start) {
var columns = [ {
text : "username",
dataIndex : 'uname',
width : 150,
filterable: true,
align : 'right'
}, {
text : "name",
dataIndex : 'fname',
width : 150,
align : 'right',
hidden : false,
sortable : true,
filterable: true,
editor : {
xtype : 'textfield',
allowBlank : false
}
}, {
text : "last name",
dataIndex : 'lname',
width : 150,
align : 'right',
sortable : true,
filterable: true,
editor : {
xtype : 'textfield',
allowBlank : false
}
}, {
text : "PostalCode",
dataIndex : 'postcode',
width : 110,
align : 'right',
sortable : true,
filterable: true,
editor : {
xtype : 'textfield',
allowBlank : false
}
}, {
text : "email",
dataIndex : 'mail',
width : 200,
align : 'right',
sortable : true,
filterable: true,
editor : {
xtype : 'textfield',
allowBlank : false
}
}, {
text : "password",
width : 150,
align : 'right',
sortable : false,
filterable: true,
hidden : true,
dataIndex : 'pass',
editor : {
xtype : 'textfield',
inputType : 'password',
allowBlank : true
}
}, {
text : "access to system",
dataIndex : 'hasAccess',
renderer:function(value){
if(value[0]=="1"){
return "has";
}else{
return "doens't have";
}
},
width : 100,
align : 'center',
sortable : false,
filterable: false
}, {
text : "active",
dataIndex : 'isActive',
renderer:function(value){
if(value==null)
return;
if(value[0]=="1"){
return "no";
}else if(value[0]=="0"){
return "yes";
}else if(value[0]=="2"){
return "Not in portal!";
}
},
width : 100,
align : 'center',
sortable : false,
filterable: false
}, {
text : "last visit",
dataIndex : 'lastVisit',
width : 120,
hidden : true,
align : 'right',
sortable : true,
filterable: true
}, {
text : " ",
dataIndex : 'uname',
renderer:function(value){
return "delete";
},
width : 120,
hidden : true,
align : 'right'
} ];
return columns.slice(start || 0, finish);
};
var pluginExpanded = true;
var grid = Ext.create('Ext.grid.Panel', {
border: false,
width : 1200,
height : 620,
title : '',
store: store,
disableSelection : false,
seltype : 'rowmodel',
loadMask : true,
viewConfig : {
id : 'gv',
trackOver : false,
stripeRows : false,
plugins : [ {
ptype : 'preview',
bodyField : 'excerpt',
expanded : true,
pluginId : 'preview'
} ]
},
columns: createColumns(),
features: [filters],
dockedItems: [Ext.create('Ext.toolbar.Paging', {
dock: 'bottom',
store: store
})],
plugins : [ Ext.create('Ext.grid.plugin.RowEditing', {
clicksToEdit : 2
}) ],
renderTo : 'userdatagrid'
});
grid.child('pagingtoolbar').add([
{
text: 'show filters',
handler: function () {
var data = Ext.encode(grid.filters.getFilterData());
Ext.Msg.alert('show filters',data);
}
},{
text: 'delete filters',
handler: function () {
grid.filters.clearFilters();
}
}
]);
store.loadPage(1);
});
Or you could use this:
grid.on('sortchange', function() {
grid.getStore().loadPage(1);
});
Forget everything I wrote:
Server Side sorting in an ExtJS GridPanel
You should put your custom function in the grid event: sortchange.
I just re-read your question - I thought you have infinite paging.
If your sort is done server side, then yes, you need to call loadPage(1).
You also need to send the sort parameters.
listeners: {
sortchange: function(){
var grid = Ext.ComponentQuery.query('my-grid-alias')[0];
grid.getStore().loadPage(1);
}
}
I hope this helps.
I just put a loadPage(1) in the sortchange event, but it made twice server request(grid made the first one with sort parameters automatically), how could it be only once?
I figure out one solution, I set "remoteSort:false" in store and
"sortchange: {fn:function(){
var time = (new Date()).getTime()/1000;
// after {remoteSort:false} is set, sortchange event will be fired twice when column header is clicked, so I had to set a parameter for time record
if('undefined' == typeof(this.last_sort_time) || this.last_sort_time+1 < time){
this.getStore().loadPage(1);
this.last_sort_time = time;
}
}, scope:this}"
in grid.
But it not works fine, because the received data was reordered by the grid before displayed on it
At last, I solve the problem in this way:
Ext.override(Ext.grid.column.Column, {
doSort:function(){
var ds = this.up('tablepanel').store;
ds.currentPage = 1;
this.callParent(arguments);
}
});
And it works perfectly so far
sortchange event fires after request is send to the server. For solution look here
http://www.sencha.com/forum/showthread.php?145779-Reset-page-for-paginator-on-sort-change
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).
I am using this article of architecture http://blog.extjs.eu/know-how/writing-a-big-application-in-ext/
here is my Application.ResellerIroGrid.js
the pagination buttons are coming but no. of pages and pageno. is not coming .
Application.ResellerIroGrid = Ext.extend(Ext.grid.GridPanel, {
border:false
,cityname : ''
,columndataindex : ''
,fromdate:''
,todate : ''
,initComponent:function() {
var config = {
store:new Ext.data.JsonStore({
// store configs
autoDestroy: true,
autoLoad :false
,method: 'GET'
,baseParams: {
_command:'getresellersiro'
,city:this.cityname
,columndataindex : this.columndataindex
,fromdate : this.fromdate
,todate : this.todate
}
,url: 'api/index.php'
// reader configs
,root: 'reseller'
,totalProperty: 'totalcount'
,idProperty: 'mobile',
fields: [
{name: 'caller'},
{name: 'designa'},
{name: 'mobile'},
{name: 'app_date'},
{name: 'transferto'},
{name: 'data_city'},
{name: 'AllocatedTo'},
{name: 'Parentid'},
{name: 'gotthru'}
]
})
,columns: [
{
id :'caller',
header : 'Caller',
width : 120,
sortable : true,
dataIndex: 'caller'
},
{
id :'designa',
header : ' Designation',
width : 100,
sortable : true,
dataIndex: 'designa'
},
{
id :'mobile',
header : 'Mobile',
height : 50,
width : 100,
sortable : true,
dataIndex: 'mobile'
},
{
id :'app_date',
header : ' Appointment Date',
width : 100,
sortable : true,
dataIndex : 'app_date'
},
{
id :'transferto',
header : ' Transfered To',
width : 100,
sortable : true,
dataIndex: 'transferto'
},
{
id :'data_city',
header : ' Data City',
width : 100,
sortable : true,
dataIndex: 'data_city'
},
{
id :'AllocatedTo',
header : ' Allocated To',
width : 100,
sortable : true,
dataIndex: 'AllocatedTo'
},
{
id :'Parentid',
header : ' Parent Id',
width : 100,
sortable : true,
dataIndex: 'Parentid'
},
{
id :'gotthru',
header : ' Appointment Type',
width : 100,
sortable : true,
dataIndex: 'gotthru'
}
]
,plugins :[]
,viewConfig :{forceFit:true}
,tbar :[]
,bbar: new Ext.PagingToolbar({
pageSize: 5,
store: this.store,
displayInfo: true,
displayMsg: 'Displaying topics {0} - {1} of {2}',
emptyMsg: "No topics to display"
})
,height : 250
,width : 860
,title : 'Reseller Iro Grid'
}; // eo config object
// apply config
Ext.apply(this, Ext.apply(this.initialConfig, config));
Application.ResellerIroGrid.superclass.initComponent.apply(this, arguments);
} // eo function initComponent
,onRender:function() {
this.store.load();
Application.ResellerIroGrid.superclass.onRender.apply(this, arguments);
} // eo function onRender
});
Ext.reg('ResellerIroGrid', Application.ResellerIroGrid);
You need to have a totalProperty attribute in your Store or JsonReader config and this property must be sent by ther server JSON.
Eg :
,totalProperty: 'totalCount'
,root: 'reseller',
,idProperty: 'caller'
Also, dont hardcode params in the store url property. You should use the baseParams config option for this :
method:'GET'
,baseParams: {
_command:'getresellersiro'
,city:this.cityname
[...]
}
,url:'api/index.php'
And of course you should have a PagingToolbar declared for your grid in the initComponent :
var pagesize = 5;
var store = new Ext.data.JsonStore({
[...]
,params:{start:0, limit:pagesize}
});
var paging_toolbar = new Ext.PagingToolbar({
pageSize: pagesize,
displayInfo: true,
emptyMsg: 'No data',
store: store
});
var grid = new Ext.grid.GridPanel({
store:store,
[...]
bbar:paging_toolbar
});