ExtJs - populating data from database to grid using actioncolumn - extjs

I have a grid with actionColumn and when I click on edit icon it should call the other form(already available) with data populated in to fields from database so that the user can edit and save it. I am new to Extjs please help
I tried with the following code but its not working:
myForm.getForm().load({
url: '/.RetrieveRecords',
params: { id: id},
method: 'POST',
waitMsg: 'Loading data...'
Here is my form1:
Ext.application({
name : 'extjs.com',
launch : function()
{
var myForm = Ext.create('Ext.form.Panel',
{
title: 'Registration Form',
id: 'form',
Layout: 'border',
border: 'true',
padding: 10,
bodyPadding: 30,
renderTo: Ext.getBody(),
defaultType: 'textfield',
items :
[
{fieldLabel: 'First Name', name: 'firstname', id: 'firstname',allowBlank: false, minLength: 2, maxLength:25, regex:/^[a-zA-Z]/},
{fieldLabel: 'Last Name', name: 'lastname', id: 'lastname', allowBlank: false, minLength: 2, maxLength:25},
{fieldLabel: 'Email', name: 'email', id: 'email',allowBlank: false, vType: 'email', msgTarget:'under'},
{fieldLabel: 'Mobile Number', name: 'mobilenumber', id: 'mobilenumber',allowBlank: false, minLength: 10, maxLength:10, regex:/^[7-9][0-9]{9}$/, regexText:"Invalid mobile number",msgTarget:"under"},
{
xtype: 'datefield',
fieldLabel: 'DOB'+'<span style="color:red;font-weight:bold" data-qtip="Required">*</span>',
name: 'dob',
id:'dob',
allowBlank: false,
value: '2 4 1978',
format: 'd m Y',
// value: new Date(),
maxValue: new Date(),
msgTarget:'side'
},
{
xtype:'radiogroup',
fieldLabel: 'Gender',
defaultType: 'radiofield',
anchor: '22.5%',
id:'gender1',
defaults:
{
flex: 1
},
layout: 'hbox',
items: [
{
boxLabel: 'Male',
name: 'rb',
inputValue: 'M',
checked: true
},
{
boxLabel: 'Female',
name: 'rb',
inputValue: 'F',
}]
},
{
xtype:'checkboxgroup',
fieldLabel: 'Known Technologies',
anchor: '50%',
id:'tech',
columns: 3,
vertical: true,
items:
[
{boxLabel: 'java', name: 'cb',inputValue: 'java', x:20, checked: true},
{boxLabel: 'c++', name: 'cb',inputValue: 'c++', x:20, checked: true},
{boxLabel: 'jsp', name: 'cb',inputValue: 'jsp', x:20, checked: false},
{boxLabel: 'javascript', name: 'cb',inputValue: 'javascript', checked: false},
{boxLabel: 'hadoop', name: 'cb',inputValue: 'hadoop', checked: false},
{boxLabel: 'spring', name: 'cb',inputValue: 'spring', checked: false}
]
},
{
xtype:'textarea',
fieldLabel: 'Hobbies',
name:'hobby',
id:'hobby',
anchor:'100%'
// padding:5
},
{
xtype:'fieldset',
title: 'Address',
collapsible:false,
items:
[
{
xtype:'combobox',
displayField:'cname',
valueField:'cid',
fieldLabel:'country'+'<span style =color:red;data-qtip="Required">*</span>',
queryMode:'local',
msgTarget: 'under',
name:'country',
id: 'country',
store: Ext.create('Ext.data.Store',{
fields:['cid','cname']
}),
listeners:
{
afterrender:function()
{
Ext.Ajax.request({
url:'./getRecords',
success: function(response)
{
var jarray = [];
jarray = Ext.JSON.decode(response.responseText);
Ext.getCmp('country').getStore().loadData(jarray);
},
failure: function(response)
{
Ext.Msg.alert('failed' + response.status);
}
});
},
change: function(a,b,c)
{
var countryID1 = Ext.getCmp('country').getValue();
Ext.Ajax.request({
url:'./getStates',
params:{countryID:countryID1},
success: function(response)
{
//alert(JSON.stringify(response));
var jarray = [];
jarray=Ext.JSON.decode(response.responseText);
Ext.getCmp('state').getStore().loadData(jarray);
},
failure: function(response)
{
Ext.Msg.alert('Failed' + response.status);
}
});
}
}
},
{
xtype:'combobox',
displayField:'sname',
valueField:'sid',
fieldLabel:'State',
name:'state',
id:'state',
queryMode:'local',
msgTarget: 'under',
store: Ext.create('Ext.data.Store',{
fields:['sid','sname']
}),
listeners:
{
change: function(a,b,c)
{
var StateID = Ext.getCmp('state').getValue();
Ext.Ajax.request({
url:'./getCities',
params: {StateID1:StateID},
success: function(response)
{
var jarray = [];
jarray = Ext.JSON.decode(response.responseText);
Ext.getCmp('city').getStore().loadData(jarray);
},
failure: function(response)
{
Ext.Msg.alert('failed' + response.status);
}
});
}
}
},
{
xtype:'combobox',
displayField:'cname',
valueField:'cid',
fieldLabel:'City',
name:'city',
id:'city',
queryMode:'local',
msgTarget: 'under',
store: Ext.create('Ext.data.Store',{
fields:['cid','cname','sid']
})
},
{
xtype:'textfield',
displayField:'PincodeName',
valueField:'pincodeID',
fieldLabel:'Pin-code',
id:'pincode',
allowBlank: false,
maskRe: /[0-9\-]/,
regex: /^[0-9]{3}(\-)?[0-9]{3}$/,
regexText:"invalid pincode",
msgTarget: 'under'
}
]
},
{
xtype:'fieldset',
title:'Education',
collasible: false,
items:
[
{
xtype:'combobox',
displayField:'QualificationName',
valueField:'QualificationID',
fieldLabel:'Qualification',
id:'qualification',
name:'qualification',
queryMode:'local',
msgTarget:'side',
store: Ext.create('Ext.data.Store',{
fields:['QualificationID','QualificationName'],
data:
[
{"QualificationID":"1","QualificationName":"B.Tech"},
{"QualificationID":"2","QualificationName":"Diploma"},
{"QualificationID":"3","QualificationName":"Advanced Diploma"}
]
}),
listeners:
{
change: function()
{
Ext.getCmp('DepartmentID').setVisible(true);
Ext.getCmp('PercentageID').setVisible(true);
}
}
},
{
xtype:'textfield',
name:'department',
id:'DepartmentID',
displayField:'Department',
valueField:'DeptID',
fieldLabel:'Department',
allowBlank: false,
hidden:true,
msgTarget: 'under'
},
{
xtype:'textfield',
name: 'percentage',
id: 'PercentageID',
displayField:'Percentage',
valueField:'PercentageID',
fieldLabel:'Percentage',
msgTarget: 'under',
regex:/^-?[0-9]{0,2}(\.[0-9]{1,2})?%?$|^-?(100)(\.[0]{1,2})?%?$/,
regexText:"invalid percentage",
hidden:true
}
]
}
],
buttons:
[
{text:'Submit',
handler: function()
{
var mail = Ext.getCmp('email').getValue();
var mnumber = Ext.getCmp('mobilenumber').getValue();
var gender = Ext.getCmp('gender1').getChecked()[0].inputValue;
var selection = [];
selection = Ext.getCmp('tech').getChecked();
var selections = "";
for(var i=0;i<selection.length;i++)
{
selections += selection[i].inputValue + " ";
}
var add = Ext.getCmp('country').getRawValue()+","+Ext.getCmp('state').getRawValue()+","+Ext.getCmp('city').getRawValue()+","+Ext.getCmp('pincode').getValue();
var edu = Ext.getCmp('qualification').getRawValue()+","+Ext.getCmp('DepartmentID').getValue()+","+Ext.getCmp('PercentageID').getValue();
var dob = Ext.getCmp('dob').getRawValue();
var hobby = Ext.getCmp('hobby').getValue();
var fname = Ext.getCmp('firstname').getValue();
var lname = Ext.getCmp('lastname').getValue();
//alert(this.up('form'));
var form = this.up('form').getForm();
if(form.isValid())
{
Ext.Ajax.request
({
url:'./Save_Records',
method: 'POST',
params: {mail1:mail,mnumber1:mnumber,gender2:gender,selections1:selections,add1:add,edu1:edu,dob1:dob,hobby1:hobby,fname1:fname,lname1:lname},
success: function(response)
{
Ext.Msg.alert("success" + response.status);
},
failure: function(response)
{
Ext.Msg.alert("failed" + response.status);
}
});
}
else
{
alert("Please fill in the form");
}
}
},
{
text:'Reset',
handler: function()
{
this.up('form').getForm().reset();
Ext.Ajax.request
({
url:'index.jsp',
method: 'POST',
success: function(response)
{
Ext.Msg.alert('Success' + " " + response.status);
},
failure: function(response)
{
Ext.Msg.alert('Failure' + " " + response.status);
}
});
}
}
]
});
}
});
Here is my Form2 with Actioncolumns:
Ext.onReady(function()
{
var store=Ext.create('Ext.data.Store',
{
autoload: true,
autosync: true,
data: [],
fields:
[
{name: 'firstname', id:'firstname'},
{name: 'email', id:'email'},
{name: 'mobileno', id:'mobileno'}
]
});
Ext.create('Ext.grid.Panel',
{
renderTo: Ext.getBody(),
height:150,
width:400,
x:200,
y:50,
store:store,
id: 'grid1',
columns:
[
{
header:'Firstname',
id:'firstname',
dataIndex:'firstname',
editor: {
xtype: 'textarea'
}
},
{
header:'Mobileno',
id:'mobileno',
dataIndex:'mobileno',
editor: {
xtype: 'textarea'
}
},
{
header:'Email',
id:'email',
dataIndex:'email',
editor: {
xtype: 'textarea'
}
},
{
header:'Action',
id:'action',
align:'center',
xtype:'actioncolumn',
sortable:false,
items:
[
{
icon:'images/view_icon.gif',
tooltip:'View',
handler: function(grid,rowIndex,colIndex)
{
var rec= grid.getStore().getAt(rowIndex);
}
},
{
icon:'images/edit_icon.gif',
tooltip:'Edit',
handler: function(grid,rowIndex,colIndex,e)
{
var rec= grid.getStore().getAt(rowIndex);
myForm.getForm().load({
// url: '/path/to/form/data',
params: { id: id},
method: 'POST',
waitMsg: 'Loading data...'
});
// Ext.Ajax.request(
// {
// url:'./RetrieveRecords',
// success: function(response)
// {
// Ext.Msg.alert("success" +" " + response.status);
// window.location.reload();
// },
// failure: function(response)
// {
// Ext.Msg.alert("failed" + response.status);
// }
// });
}
},
{
icon:'images/icons/cancel.png',
tooltip:'Delete',
handler: function(grid,rowIndex,colIndex)
{
var rec= grid.getStore().getAt(rowIndex);
var email = rec.get('email');
Ext.Ajax.request(
{
url:'./deleteRecords',
params:{email:email},
success: function(response)
{
Ext.Msg.alert("successfully deleted" +" " + response.status);
window.location.reload();
},
failure: function(response)
{
Ext.Msg.alert("failed" + response.status);
}
});
}
}
]
}
],
selType: 'cellmodel',
plugins:
[
Ext.create('Ext.grid.plugin.CellEditing',
{
clicksToEdit: 1
})
],
listeners:
{
afterrender:function()
{
Ext.Ajax.request(
{
params:{email:email},
url:'./RetrieveRecords',
success: function(response)
{
data = [];
data = Ext.JSON.decode(response.responseText);
Ext.getCmp('grid1').getStore().loadData(data);
},
failure: function(response)
{
Ext.Msg.alert("failure" + " " + response.status);
}
});
}
}
});
});

Try following as edit button:
handler: function(grid, rowIndex, colIndex, e) {
var rec = grid.getStore().getAt(rowIndex);
myForm.loadRecord(rec);
}

Related

Deleting the row is not updating the grid? Sencha Extjs Application

When I delete any current row, the next row and pagination has to get updated in the empty row. But it is not updating the pagination but the url is passing in network correctly. When I refresh the page, the empty row is replaced by the next row.
List.js:
/**
* This view is an example list of people.
*/
Ext.define('CRUD.view.main.List', {
extend: 'Ext.grid.Panel',
xtype: 'home',
requires: [
'CRUD.store.Personnel',
'CRUD.view.main.MainController',
'Ext.toolbar.Paging',
],
title: 'Heroes',
plugins: [
Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1
})
],
layout: 'fit',
fullscreen: true,
store: {
type: 'personnel',
},
selModel: {
pruneRemoved: false
},
selType: 'cellmodel',
columns: [{
text: 'Name',
align: 'center',
dataIndex: 'name',
sortable: true,
flex: 1,
editor: {
xtype: 'textfield',
selectOnFocus: true,
allowBlank: false
}
},
{
text: 'Email',
align: 'center',
dataIndex: 'email',
sortable: true,
flex: 1,
editor: {
xtype: 'textfield',
selectOnFocus: true,
allowBlank: false
}
},
{
text: 'Phone',
align: 'center',
dataIndex: 'phone',
sortable: true,
flex: 1,
editor: {
xtype: 'textfield',
selectOnFocus: true,
allowBlank: false
}
},
{
text: 'Save',
align: 'center',
xtype: 'actioncolumn',
items: [{
icon: 'http://icons.iconarchive.com/icons/oxygen-icons.org/oxygen/128/Actions-document-edit-icon.png',
xtype: 'submit',
handler: function(grid, rowIndex, colIndex, item, e, record) {
Ext.Msg.confirm("Confirmation", "Do you want to Save?", function(btnText) {
if (btnText === "yes") {
Ext.Ajax.request({
url: 'http://localhost:8080/edit?id=' + record.data.id + '&name=' + record.data.name + '&email=' + record.data.email + '&phone=' + record.data.phone,
method: 'POST', //this is the url where the form gets submitted
useDefaultXhrHeader: false,
success: function(response) {
store.load()
},
failure: function(form, action) {
Ext.Msg.alert('Failed', action);
}
});
}
});
}
}],
}, {
text: 'Delete',
xtype: 'actioncolumn',
align: 'center',
items: [{
icon: 'http://www.freeiconspng.com/uploads/delete-button-png-27.png',
xtype: 'submit',
// handler: function(grid, rowIndex, colIndex, item, e, record) {
// console.log(record.data.id)
// // Ext.Msg.confirm('Confirmation', 'Are you sure?', function(btnText) {
// // if (btnText === 'yes') {
// // Ext.Ajax.request({
// // url: 'http://localhost:8080/del/' + record.data.id,
// // method: 'DELETE', //this is the url where the form gets submitted
// // useDefaultXhrHeader: false,
// // cors: true,
// // success: function(form, action) {
// // store.load()
// // },
// // failure: function(form, action) {
// // Ext.Msg.alert('Failed', action);
// // }
// // });
// // }
// // })
// }
}],
listeners: {
click: 'onDeleteClick'
}
}
],
bbar: Ext.create('Ext.PagingToolbar', {
xtype: 'pagingtoolbar',
displayInfo: true,
doRefresh: function() {
this.doLoad(this.cursor);
},
}),
// columns: [
// { text: 'Name', dataIndex: 'name', flex: 1 },
// { text: 'Email', dataIndex: 'email', flex: 1 },
// { text: 'Phone', dataIndex: 'phone', flex: 1 }
// ],
// listeners: {
// select: 'onItemSelected',
// },
});
Store:
Ext.define('CRUD.store.Personnel', {
extend: 'Ext.data.Store',
alias: 'store.personnel',
model: 'CRUD.model.User',
fields: [
'name', 'email', 'phone'
],
// data: [
// { name: 'Jean Luc', email: "jeanluc.picard#enterprise.com", phone: "555-111-1111" },
// { name: 'Worf', email: "worf.moghsson#enterprise.com", phone: "555-222-2222" },
// { name: 'Deanna', email: "deanna.troi#enterprise.com", phone: "555-333-3333" },
// { name: 'Data', email: "mr.data#enterprise.com", phone: "555-444-4444" }
// ],
autoLoad: { offset: 0, limit: 5 },
pageSize: 5,
proxy: {
type: 'ajax', //cross domain calls - json parser
enablePaging: true,
url: 'http://localhost:8080/list',
useDefaultXhrHeader: false,
startParam: 'offset',
limitParam: 'limit',
reader: {
totalProperty: 'total',
rootProperty: 'items'
},
listeners: {
//this is used to construct the proxy url before the load is done
// beforeload: {
// fn: function() {
// var me = this;
// me.updateProxyURL(); //write this function yourself
// }
// }
}
},
// proxy: {
// type: 'memory',
// reader: {
// type: 'json',
// }
// },
});
Controller.js
/**
* This class is the controller for the main view for the application. It is specified as
* the "controller" of the Main view class.
*
* TODO - Replace this content of this view to suite the needs of your application.
*/
Ext.define('CRUD.view.main.MainController', {
extend: 'Ext.app.ViewController',
alias: 'controller.main',
store: {
type: 'personnel',
},
onClick: function(grid) {
Ext.Msg.alert("tesdt")
},
onDeleteClick: function(selModel, record, index, options, grid, store) {
//Ext.Msg.confirm('Confirm', 'Are you sure?', 'onConfirm', this);
Ext.Msg.confirm({
title: 'Confirm',
msg: 'Are you sure?',
buttons: Ext.Msg.OKCANCEL,
fn: this.onConfirm,
icon: Ext.MessageBox.QUESTION,
config: {
grid: grid,
action: 'del',
store: store
}
});
},
onConfirm: function(btn, text, opt) {
console.log(opt.config.action)
if (btn === 'ok') {
//
opt.config.grid.item.remove();
Ext.Ajax.request({
url: 'http://localhost:8080/' + opt.config.action + '/' + opt.config.grid.record.data.id,
// method: 'DELETE', //this is the url where the form gets submitted
useDefaultXhrHeader: false,
success: function(form, action) {
opt.config.store.load({
start: 0,
limit: 5
})
},
failure: function(form, action) {
},
listeners: {
doRefresh: function() {
this.doLoad(this.cursor);
},
}
});
}
}
});
Please find the screenshot here
Doing grid.getStore().reload() should be sufficient.
BTW. The doRefresh listener is weird. Are you sure you wanted this as Ext.Ajax.request config? This doesn't make sense to me.

Best way to block CTRL-V against a grid

Using the following fiddler https://fiddle.sencha.com/#fiddle/1frn
You can select cell, do CTRL-C, then select different cell, and do CTRL-V and you see the values have been copied.
How do I block CTRL-V?
Is overriding clipboard.validateAction the best way?
privates : {
validateAction : function(event) {
var view = this.getCmp().getView();
If(view.actionableMode){
return false;
}
}
}
Its not clear to me why a common function like validateAction would be private...
You can use this override/sample code to control the ability to paste depending on the current state of the grid:
Ext.define('Fiddle.grid.plugin.Clipboard',{
override: 'Ext.grid.plugin.Clipboard',
beforepaste: Ext.emptyFn,
mixins: [
'Ext.mixin.Observable'
],
constructor: function(config) {
var me = this;
me.callParent([config]);
me.mixins.observable.constructor.call(me);
},
privates : {
onPaste: function (keyCode, event) {
var me = this,
sharedData = me.shared.data,
source = me.getSource(),
i, n, s;
if (me.validateAction(event) === false) {
return;
}
if (me.fireEvent('beforepaste',keyCode,event,me.cmp) !== false) {
if (source) {
for (i = 0, n = source.length; i < n; ++i) {
s = source[i];
if (s === 'system') {
// get the format used by the system clipboard.
s = me.getSystem();
me.pasteClipboardData(s);
break;
} else if (sharedData && (s in sharedData)) {
me.doPaste(s, sharedData[s]);
break;
}
}
}
}
}
}
});
Ext.define('UserController', {
extend : 'Ext.app.ViewController',
alias: 'controller.users',
onBeforePaste:function(keyCode,event,grid){
//Perform custom logic
console.log(grid)
return false;
}
});
Ext.application({
name: 'Fiddle',
launch: function() {
var store = Ext.create('Ext.data.Store', {
fields: ['name', 'email', 'phone'],
data: [{
name: 'Lisa',
email: 'lisa#simpsons.com',
phone: '555-111-1224'
}, {
name: 'Bart',
email: 'bart#simpsons.com',
phone: '555-222-1234'
}, {
name: 'Homer',
email: 'homer#simpsons.com',
phone: '555-222-1244'
}, {
name: 'Marge',
email: 'marge#simpsons.com',
phone: '555-222-1254'
}]
});
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: store,
controller:'users',
width: 400,
renderTo: Ext.getBody(),
columns: [{
text: 'Name',
dataIndex: 'name'
}, {
text: 'Email',
dataIndex: 'email',
flex: 1
}, {
text: 'Phone',
dataIndex: 'phone'
}],
plugins: {
ptype: 'cellediting',
clicksToEdit: 2
},
selModel: {
type: 'spreadsheet',
rowNumbererHeaderWidth: 0
},
plugins: [{
ptype: 'clipboard',
listeners: {
beforepaste: 'onBeforePaste'
}
}],
listeners: {
selectionchange: function(grid, selection, eOpts) {
var store = grid.getStore();
}
}
});
}
});

How to render date in right timezone extjs 6?

Im new in extjs.
I have a grid.
When i add new row script automaticaly puts there time time_start = Ext.Date.format(new Date(), '2008-01-01\\TH:i:s'); and its work fine, extjs automaticaly sends to server time.
But when i look at a grid there is a time +3 hours.
For example if my local time is 23.00.00, extjs send to server "2008-01-01T23:00:00", but shows in a grid "02:00".
But it must show "23:00".
Its add +3 hours to a cell view, whats wrong ?
Ext.require(['Ext.data.*', 'Ext.grid.*']);
// Создаем model
Ext.define('Users', {
extend: 'Ext.data.Model',
//idProperty: 'id',
fields: [{
name: 'id',
type: 'int'
}
]
});
Ext.onReady(function() {
// Создаем store
var store = Ext.create('Ext.data.Store', {
autoLoad: true,
autoSync: true,
model: 'Users',
proxy: {
type: 'ajax',
url: 'server.php',
api: {
create: 'server.php?action=create',
read: 'server.php?action=read',
update: 'server.php?action=update',
destroy: 'server.php?action=delete'
},
reader: {
type: 'json',
rootProperty: 'data'
},
writer: {
type: 'json',
encode: true,
rootProperty: 'dataUpdate',
allowSingle: false,
writeAllFields: true,
//root:'records'
},
actionMethods: {
create: 'GET',
read: 'GET',
update: 'GET',
destroy: 'GET'
}
},
listeners: {
write: function(store, operation) {
var record = operation.getRecords()[0],
name = Ext.String.capitalize(operation.action),
verb;
if (name == 'Destroy') {
verb = 'Destroyed';
} else {
verb = name + 'd';
}
//Ext.example.msg(name, Ext.String.format("{0} user: {1}", verb, record.getId()));
}
}
}
);
var grid = Ext.create('Ext.grid.Panel', {
renderTo: document.body,
//plugins: [rowEditing],
// Редактирование
plugins: {
ptype: 'cellediting',
clicksToEdit: 1
},
listeners: {
edit: function() {
}
},
width: 1000,
height: 330,
frame: true,
title: 'Users',
store: store,
iconCls: 'icon-user',
columns: [{
text: 'id',
width: 50,
sortable: true,
dataIndex: 'id',
renderer: function(v, meta, rec) {
return rec.phantom ? '' : v;
}
},
{
header: 'Дата',
width: 70,
// sortable: true,
dataIndex: 'date',
renderer: Ext.util.Format.dateRenderer('d/m/Y'),
editor: {
completeOnEnter: false,
field: {
xtype: 'datefield',
dateFormat: 'd/m/Y',
allowBlank: false
}
}
},
{
header: 'Время начала',
width: 120,
// sortable: true,
dataIndex: 'time_start',
//format: 'H:i',
// Нужно для верного отображеия времени после редактирования в таблице
renderer: Ext.util.Format.dateRenderer('H:i'),
editor: {
completeOnEnter: false,
field: {
xtype: 'timefield',
format: 'H:i',
//name: 'timeStart1',
//fieldLabel: 'Time In',
minValue: '8:00',
maxValue: '20:00',
increment: 30,
anchor: '100%',
allowBlank: false
}
}
}
],
dockedItems: [{
xtype: 'toolbar',
items: [{
text: 'Add',
iconCls: 'icon-add',
handler: function() {
// Создаем новую задачу
// Для корректной работы с БД нужно задать ID новой строки, равной +1 от последней ID из таблицы.
var rec = new Users();
//console.log (x);("rec data= " + rec.id + " -- " + rec.data.id);
var idArr = grid.store.data.items;
var idValue = [];
for (var i = 0; i < idArr.length; i++) {
idValue.push(idArr[i].id);
}
idValue.sort(function(a, b) {
return a - b;
});
var maxId = idValue[idValue.length - 1];
console.log(maxId);
rec.id = maxId + 1;
rec.data.id = maxId + 1;
rec.date = Ext.Date.format(new Date(), 'Y-m-d');
rec.data.date = Ext.Date.format(new Date(), 'Y-m-d');
rec.time_start = Ext.Date.format(new Date(), '2008-01-01\\TH:i:s');
rec.data.time_start = Ext.Date.format(new Date(), '2008-01-01\\TH:i:s');
store.insert(0, rec);
//store.add(rac);
//grid.getView().refresh();
// rowEditing.startEdit(rec, 0);
}
}, '-', {
itemId: 'delete',
text: 'Delete',
iconCls: 'icon-delete',
disabled: false,
handler: function() {
var selection = grid.getView().getSelectionModel().getSelection()[0];
if (confirm('Вы действительно хотите удалить задачу №' + selection.id + " ?")) {
// Удлаяем
if (selection) {
store.remove(selection);
}
}
}
}]
}]
});
});
You have to write renderer on column
renderer : function(value){
var serverDate = new Date(value{2015-12-04T10:39:22});
var newFrmDate = Ext.Date.format(serverDate,'m-d-Y h:i A');
return newFrmDate;
}
you can specify your own date time format.

Make gridpanel checkbox readonly by default

I have a gridpanel with few items and checkboxes. i want a specific item in the gridpanel to be checked and readonly by default (the checked value cannot be changed by user). How should i do that? My code is as follows:
var MyCheckboxModel = Ext.create('Ext.selection.CheckboxModel', {
mode : 'SIMPLE',
listeners : {
selectionchange : function(selectionModel) {
}
},
});
var userCheckboxContainersStore = Ext.create('Ext.data.Store', {
storeId: 'userCheckboxStore',
fields: ['data'],
data: [
{ data: 'Item 1'},
{ data: 'Item 2' },
{ data: 'Item 3'},
{ data: 'Item 4'},
{ data: 'Item 5'},
]
});
var userCheckboxGridPanel = Ext.create('Ext.grid.Panel', {
layout : {
type : 'vbox',
align : 'stretch'
},
defaults : {
border : 0,
bodyStyle : {
backgroundColor : 'transparent'
}
},
store: CheckboxContainersStore,
selModel: MyCheckboxModel,
title: 'Item List',
columns: [
{ dataIndex: 'data'},
]
});
I want 'Item 1' to be checked by default and readonly. Any suggestions would be appreciated
You need something like this, here you can try a fiddle
You can't work with readonly true, but instead you can work with selections of the grid, and make sure the item1 will never be unselected.
Ext.application({
name: 'Fiddle',
launch: function () {
var MyCheckboxModel = Ext.create('Ext.selection.CheckboxModel', {
mode: 'SIMPLE',
listeners: {
selectionchange: function (selectionModel) {}
},
});
var userCheckboxContainersStore = Ext.create('Ext.data.Store', {
storeId: 'userCheckboxStore',
fields: ['data'],
data: [{
data: 'Item 1'
}, {
data: 'Item 2'
}, {
data: 'Item 3'
}, {
data: 'Item 4'
}, {
data: 'Item 5'
},
]
});
var userCheckboxGridPanel = Ext.create('Ext.grid.Panel', {
layout: {
type: 'vbox',
align: 'stretch'
},
defaults: {
border: 0,
bodyStyle: {
backgroundColor: 'transparent'
}
},
store: userCheckboxContainersStore,
selModel: MyCheckboxModel,
title: 'Item List',
columns: [{
dataIndex: 'data'
}],
listeners: {
render: function (gridPanel) {
gridPanel.setSelection(userCheckboxContainersStore.getAt(0));
gridPanel.on('itemclick', function (panel, selected) {
if (selected.id === userCheckboxContainersStore.getAt(0).id) {
var newSelection = gridPanel.getSelection();
if (newSelection.indexOf(selected) === -1)
newSelection.push(selected);
gridPanel.setSelection(newSelection);
}
});
}
},
renderTo: Ext.getBody()
});
}
});
Another way of implementation would be like this.
var MyCheckboxModel = Ext.create('Ext.selection.CheckboxModel', {
mode: 'SIMPLE',
checkOnly: true,
listeners: {
beforedeselect: function(grid, record, index, eOpts) {
if (record.get('data') == "Item 1") {
return false;
}
}
}
});
var userCheckboxContainersStore = Ext.create('Ext.data.Store', {
storeId: 'userCheckboxStore',
fields: ['data'],
data: [{
data: 'Item 1'
}, {
data: 'Item 2'
}, {
data: 'Item 3'
}, {
data: 'Item 4'
}, {
data: 'Item 5'
},
]
});
var userCheckboxGridPanel = Ext.create('Ext.grid.Panel', {
layout: {
type: 'vbox',
align: 'stretch'
},
defaults: {
border: 0,
bodyStyle: {
backgroundColor: 'transparent'
}
},
listeners: {
'viewready': function(grid) {
grid.selModel.doSelect(grid.store.data.items[0]);
}
},
store: userCheckboxContainersStore,
selModel: MyCheckboxModel,
title: 'Item List',
columns: [{
dataIndex: 'data'
}],
renderTo: Ext.getBody()
});
Updated Fiddle: http://jsfiddle.net/y61yo7sx/1/

Extjs Tree context menu mixes on second open

Below, When I close and reopen the window, 'projeler', contextmenu of the tree damages itself. When I reopen the window, only first item damages itself. It seems like there are two labels mixed together. I tried to delete 'generalCreationButtonStatus' but I got same error on first item of the menu.
Could you please help?
Ext.define('MyDesktop.Projeler', {
extend: 'Ext.ux.desktop.Module',
requires: [
'Ext.util.Format',
'Ext.grid.Panel',
'Ext.grid.RowNumberer',
'Ext.tree.*',
'Ext.data.*',
'Ext.tip.*'
],
id:'tree-projeler',
init : function(){
this.launcher = {
text: 'Projeler',
iconCls:'projectManage-shortcut'
};
},
createWindow : function(){
var projectCreationWin = new Ext.Window({
layout:'form',
title: 'Proje Oluşturma',
closeAction:'hide',
plain: true,
width: 250,
height: 200,
modal : true,
resizable:false,
items:[
{
xtype:'textfield',
fieldLabel: 'Proje Kodu',
emptyText: 'Proje Kodu Yazınız...',
name:'projectCreationWin_projectCode_name',
id:"projectCreationWin_projectCode_id",
width: 100,
anchor: '100%'
},
{
xtype:'textfield',
fieldLabel: 'Proje Adı',
emptyText: 'Proje Adı Yazınız...',
name:'projectCreationWin_projectName_name',
id:"projectCreationWin_projectName_id",
width: 100,
anchor: '100%'
},
],
buttons: [{
text: 'Oluştur',
handler: function(){
var selectedNode = projelerTree.getSelectionModel().getSelection();
var projectCode= Ext.getCmp("projectCreationWin_projectCode_id");
var projectCode= projectCode.getValue();
var projectName= Ext.getCmp("projectCreationWin_projectName_id");
var projectName= projectName.getValue();
Ext.Ajax.request({
url: 'phps/treeloader.php',
params:{
'process':'addNode',
'subProccess': 'addProject',
'code':projectCode,
'name':projectName,
'node': selectedNode[0].data.id,
'depth': '1'
},
success: function(response, options) {
Ext.Msg.alert('Dikkat!','İşleminiz Başarıyla Gerçekleştirilmiştir !');
},
failure: function(response, options) {
Ext.Msg.alert('Dikkat!','İşleminiz Gerçekleştirilemedi!');
}
});
}
},{
text:'Vazgeç',
handler: function(){
}
}],
listeners:{
beforeshow:function(){
}
}
})
var contractCreationWin = new Ext.Window({
layout:'form',
title: 'Kontrat Oluşturma',
closeAction:'hide',
plain: true,
width: 300,
height: 300,
modal : true,
resizable:false,
items:[
{
xtype:'textfield',
fieldLabel: 'Kontrat Numarası',
emptyText: 'Kontrat Numarası Yazınız...',
name:'contractCreationWin_contractNo_name',
id:"contractCreationWin_contractNo_id",
width: 100,
anchor: '100%'
},
{
xtype:'textfield',
fieldLabel: 'Sas Numarası',
emptyText: 'Sas Numarası Yazınız...',
name:'contractCreationWin_PONo_name',
id:"contractCreationWin_PONo_id",
width: 100,
anchor: '100%'
},
{
xtype: 'radiogroup',
fieldLabel: 'Single Column',
columns: 1,
items: [
{
boxLabel: 'PAC',
name: '222',
inputValue: 1,
id: 'contractCreationWin_RadioPAC_id',
},
{
boxLabel: 'PAT',
name: '222',
inputValue: 2,
id: 'contractCreationWin_RadioPAT_id',
},
]
}
],
buttons: [{
text: 'Oluştur',
handler:
function(){
var selectedNode = projelerTree.getSelectionModel().getSelection();
var contractNo= Ext.getCmp("contractCreationWin_contractNo_id");
var contractNo= contractNo.getValue();
var customerPO= Ext.getCmp("contractCreationWin_PONo_id");
var customerPO= customerPO.getValue();
var ifPAC = Ext.getCmp('contractCreationWin_RadioPAC_id');
var ifPAC= ifPAC.getValue();
if(ifPAC == true){
var contractType = 'PAC';
}else{
var contractType = 'PAT';
}
Ext.Ajax.request({
url: 'phps/treeloader.php',
params:{
'process':'addNode',
'subProccess': 'addContract',
'code':contractNo,
'name':customerPO,
'parentId': selectedNode[0].data.id,
'depth': '3',
contractType: contractType ,
},
success: function(response, options) {
Ext.Msg.alert('Dikkat!','İşleminiz Başarıyla Gerçekleştirilmiştir !');
},
failure: function(response, options) {
Ext.Msg.alert('Dikkat!','İşleminiz Gerçekleştirilemedi!');
}
});
}
},{
text:'Vazgeç',
handler: function(){
alert(this.getValue(true));
}
}],
listeners:{
beforeshow:function(){
}
}
})
function generalCreationButtonStatus(){
if (projelerTree.getSelectionModel().hasSelection()) {
var selectedNode = projelerTree.getSelectionModel().getSelection();
if(selectedNode[0].data.depth==0){
Ext.getCmp('tree-context-proje-olustur').show();
}else{
Ext.getCmp('tree-context-proje-olustur').hide();
}
if(selectedNode[0].data.depth==1){
Ext.getCmp('tree-context-faz-olustur').show();
}else{
Ext.getCmp('tree-context-faz-olustur').hide();
}
if(selectedNode[0].data.depth==2){
Ext.getCmp('tree-context-kontrat-olustur').show();
}else{
Ext.getCmp('tree-context-kontrat-olustur').hide();
}
if(selectedNode[0].data.depth==3){
Ext.getCmp('tree-context-saha-olustur').show();
}else{
Ext.getCmp('tree-context-saha-olustur').hide();
}
}
}
var projelerTereeRclckMenu = new Ext.menu.Menu({
listeners:{
beforeShow: function(){
projelerTereeRclckMenu
generalCreationButtonStatus();
}
},
items: [
{
text: 'Sil',
id: 'tree-context-sil',
handler : function(){ alert('Sil butonuna tıklandı'); },
},
{
text: 'Proje Oluştur',
id: 'tree-context-proje-olustur',
handler : function(){
projectCreationWin.show();
}
},
{
text: 'Faz Oluştur',
id: 'tree-context-faz-olustur',
handler : function(){
var selectedNode = projelerTree.getSelectionModel().getSelection();
Ext.Ajax.request({
url: 'phps/treeloader.php',
params:{
'process':'addNode',
'subProccess': 'addPhase',
'parentId': selectedNode[0].data.id,
'depth': '2'
},
success: function(response, options) {
Ext.Msg.alert('Dikkat!','İşleminiz Başarıyla Gerçekleştirilmiştir !');
},
failure: function(response, options) {
Ext.Msg.alert('Dikkat!','İşleminiz Gerçekleştirilemedi!');
}
});
}
},
{
text: 'Kontrat Oluştur',
id: 'tree-context-kontrat-olustur',
handler : function(){
contractCreationWin.show();
},
},
{
text: 'Saha Oluştur',
handler : function(){ alert('Sil butonuna tıklandı'); },
id: 'tree-context-saha-olustur',
}
]
});
var projelerTreeStore = Ext.create('Ext.data.TreeStore', {
proxy: {
type: 'ajax',
actionMethods: 'post',
url: 'phps/treeloader.php',
extraParams: {
process:'callNode',
}
},
root: {
text: 'Root Node',
id: '0',
parentid:'0',
expanded: false,
},
folderSort: true,
sorters: [{
property: 'text',
direction: 'ASC'
}]
});
var projelerTree = Ext.create('Ext.tree.Panel', {
store: projelerTreeStore,
id:'projelerTree-id',
renderTo: Ext.getBody(),
height: 300,
width: 250,
title: 'PMT Ağaç Yapısı',
tbar : [{
text:'Yenile',
handler: function(){
},
{
text: 'add node',
handler: function() {
if (projelerTree.getSelectionModel().hasSelection()) {
var selectedNode = projelerTree.getSelectionModel().getSelection();
Ext.MessageBox.prompt('Add Node', 'Please enter node text:', function(btn, text){
if (btn == 'ok'){
Ext.Ajax.request({
url: 'phps/treeloader.php',
params: {
nodetext: text,
parentid : selectedNode[0].data.id,
depth: selectedNode[0].data.depth,
process: 'addNode'
},
success: function(response){
var id = response.responseText;
if (id > 0) {
selectedNode[0].set('leaf', false);
alert('success');
selectedNode[0].appendChild({
leaf: true,
text: text,
id: id,
});
}
}
});
}
});
} else {
Ext.MessageBox.alert('Uyarı!', 'Lütfen node eklemek istediğiniz yeri seçiniz!');
}
}
}],
listeners: {
render: function() {
Ext.getBody().on("contextmenu", Ext.emptyFn, null, {preventDefault: true});
},
itemcontextmenu : function( view, record, item, index, event){
x = event.browserEvent.clientX;
y = event.browserEvent.clientY;
projelerTereeRclckMenu.showAt([x,y]);
},
click: {
element: 'el', //bind to the underlying el property on the panel
fn: function(){
}
},
dblclick: {
element: 'body', //bind to the underlying body property on the panel
fn: function(){
Ext.getBody().on("contextmenu", Ext.emptyFn, null, {preventDefault: true});
}
},
}
});
var desktop = this.app.getDesktop();
var win = desktop.getWindow('tree-projeler');
if(!win){
var win = desktop.createWindow({
id: 'window-projeler',
closeAction: 'hide',
title:'Projeler',
width:600,
height:400,
iconCls: 'projectManage-shortcut',
animCollapse:false,
border: false,
hideMode: 'offsets',
layout: 'fit',
items: [
projelerTree,
]
});
}
return win;
},
});
I solved the problem by deleting id's of context menü items, then I needed to devide 'projelerTereeRclckMenu' accoeding to depth of tree. And I finally prepared if condition under riğght click function that shows needed context menü accordin to depth of tree:
/*!
* Ext JS Library 4.0
* Copyright(c) 2006-2011 Sencha Inc.
* licensing#sencha.com
* http://www.sencha.com/license
*/
Ext.define('MyDesktop.Projeler', {
extend: 'Ext.ux.desktop.Module',
requires: [
//'Ext.data.ArrayStore',
'Ext.util.Format',
'Ext.grid.Panel',
'Ext.grid.RowNumberer',
'Ext.tree.*',
'Ext.data.*',
'Ext.tip.*'
],
id:'tree-projeler',
init : function(){
this.launcher = {
text: 'Projeler',
iconCls:'projectManage-shortcut'
};
},
createWindow : function(){
var projectCreationWin = new Ext.Window({
layout:'form',
title: 'Proje Oluşturma',
closeAction:'hide',
plain: true,
width: 250,
height: 200,
modal : true,
resizable:false,
items:[
{
xtype:'textfield',
fieldLabel: 'Proje Kodu',
emptyText: 'Proje Kodu Yazınız...',
name:'projectCreationWin_projectCode_name',
id:"projectCreationWin_projectCode_id",
width: 100,
anchor: '100%'
},
{
xtype:'textfield',
fieldLabel: 'Proje Adı',
emptyText: 'Proje Adı Yazınız...',
name:'projectCreationWin_projectName_name',
id:"projectCreationWin_projectName_id",
width: 100,
anchor: '100%'
},
],
buttons: [{
text: 'Oluştur',
handler: function(){
var selectedNode = projelerTree.getSelectionModel().getSelection();
var projectCode= Ext.getCmp("projectCreationWin_projectCode_id");
var projectCode= projectCode.getValue();
var projectName= Ext.getCmp("projectCreationWin_projectName_id");
var projectName= projectName.getValue();
Ext.Ajax.request({
url: 'phps/treeloader.php',
params:{
'process':'addNode',
'subProccess': 'addProject',
'code':projectCode,
'name':projectName,
'node': selectedNode[0].data.id,
'depth': '1'
},
success: function(response, options) {
Ext.Msg.alert('Dikkat!','İşleminiz Başarıyla Gerçekleştirilmiştir !');
},
failure: function(response, options) {
Ext.Msg.alert('Dikkat!','İşleminiz Gerçekleştirilemedi!');
}
});
}
},
{
text:'Vazgeç',
handler: function(){
}
}],
listeners:{
beforeshow:function(){
}
}
})
var contractCreationWin = new Ext.Window({
layout:'form',
title: 'Kontrat Oluşturma',
closeAction:'hide',
plain: true,
width: 300,
height: 300,
modal : true,
resizable:false,
items:[
{
xtype:'textfield',
fieldLabel: 'Kontrat Numarası',
emptyText: 'Kontrat Numarası Yazınız...',
name:'contractCreationWin_contractNo_name',
id:"contractCreationWin_contractNo_id",
width: 100,
anchor: '100%'
},
{
xtype:'textfield',
fieldLabel: 'Sas Numarası',
emptyText: 'Sas Numarası Yazınız...',
name:'contractCreationWin_PONo_name',
id:"contractCreationWin_PONo_id",
width: 100,
anchor: '100%'
},
{
xtype: 'radiogroup',
fieldLabel: 'Single Column',
columns: 1,
items: [
{
boxLabel: 'PAC',
name: '222',
inputValue: 1,
id: 'contractCreationWin_RadioPAC_id',
},
{
boxLabel: 'PAT',
name: '222',
inputValue: 2,
id: 'contractCreationWin_RadioPAT_id',
//checked: true
},
]
}
],
buttons: [{
text: 'Oluştur',
handler:
function(){
var selectedNode = projelerTree.getSelectionModel().getSelection();
var contractNo= Ext.getCmp("contractCreationWin_contractNo_id");
var contractNo= contractNo.getValue();
var customerPO= Ext.getCmp("contractCreationWin_PONo_id");
var customerPO= customerPO.getValue();
var ifPAC = Ext.getCmp('contractCreationWin_RadioPAC_id');
var ifPAC= ifPAC.getValue();
//alert(JSON.stringify(ifPACPAT));
if(ifPAC == true){
var contractType = 'PAC';
}else{
var contractType = 'PAT';
}
Ext.Ajax.request({
url: 'phps/treeloader.php',
params:{
'process':'addNode',
'subProccess': 'addContract',
'code':contractNo,
'name':customerPO,
'parentId': selectedNode[0].data.id,
'depth': '3',
contractType: contractType ,
},
success: function(response, options) {
Ext.Msg.alert('Dikkat!','İşleminiz Başarıyla Gerçekleştirilmiştir !');
},
failure: function(response, options) {
Ext.Msg.alert('Dikkat!','İşleminiz Gerçekleştirilemedi!');
}
});
}
},
{
text:'Vazgeç',
handler: function(){
alert(this.getValue(true));
}
}],
listeners:{
beforeshow:function(){
}
}
})
function generalCreationButtonStatus(){
if (projelerTree.getSelectionModel().hasSelection()) {
}
}
//function RCLCK(){
var projelerTereeRclckMenu = new Ext.menu.Menu({
listeners:{
beforeShow: function(){
//projelerTereeRclckMenu
generalCreationButtonStatus();
}
},
items:[
{
text: 'Sil',
name: 'tree-context-sil',
listeners: {
beforeshow:
function(){
var selectedNode = projelerTree.getSelectionModel().getSelection();
alert(selectedNode[0].data.depth);
if(selectedNode[0].data.depth==1){
this.hide;
alert('222');
}else{
this.show();
}
},
},
handler : function(){ alert(JSON.stringify(projelerTereeRclckMenu.items[0])); },
},
{
text: 'Proje Oluştur',
name: 'tree-context-proje-olustur',
handler :
function(){
projectCreationWin.show();
}
},
]
});
var fazlarTereeRclckMenu = new Ext.menu.Menu({
listeners:{
beforeShow: function(){
generalCreationButtonStatus();
}
},
items:[
{
text: 'Sil',
name: 'tree-context-sil',
listeners: {
beforeshow:
function(){
var selectedNode = projelerTree.getSelectionModel().getSelection();
alert(selectedNode[0].data.depth);
if(selectedNode[0].data.depth==1){
this.hide;
alert('222');
}else{
this.show();
}
},
},
handler : function(){ alert(JSON.stringify(projelerTereeRclckMenu.items[0])); },
},
{
text: 'Faz Oluştur',
name: 'tree-context-faz-olustur',
handler :
function(){
var selectedNode = projelerTree.getSelectionModel().getSelection();
Ext.Ajax.request({
url: 'phps/treeloader.php',
params:{
'process':'addNode',
'subProccess': 'addPhase',
'parentId': selectedNode[0].data.id,
'depth': '2'
},
success:
function(response, options) {
Ext.Msg.alert('Dikkat!','İşleminiz Başarıyla Gerçekleştirilmiştir !');
},
failure:
function(response, options) {
Ext.Msg.alert('Dikkat!','İşleminiz Gerçekleştirilemedi!');
}
});
}
},
]
});
var kontratlarTereeRclckMenu = new Ext.menu.Menu({
listeners:{
beforeShow: function(){
generalCreationButtonStatus();
}
},
items:[
{
text: 'Sil',
name: 'tree-context-sil',
listeners: {
beforeshow:
function(){
var selectedNode = projelerTree.getSelectionModel().getSelection();
alert(selectedNode[0].data.depth);
if(selectedNode[0].data.depth==1){
this.hide;
alert('222');
}else{
this.show();
}
},
},
handler : function(){ alert(JSON.stringify(projelerTereeRclckMenu.items[0])); },
},
{
text: 'Kontrat Oluştur',
name: 'tree-context-kontrat-olustur',
handler :
function(){
contractCreationWin.show();
},
},
]
});
var sahalarTereeRclckMenu = new Ext.menu.Menu({
listeners:{
beforeShow: function(){
generalCreationButtonStatus();
}
},
items:[
{
text: 'Sil',
name: 'tree-context-sil',
listeners: {
beforeshow:
function(){
var selectedNode = projelerTree.getSelectionModel().getSelection();
alert(selectedNode[0].data.depth);
if(selectedNode[0].data.depth==1){
this.hide;
alert('222');
}else{
this.show();
}
},
},
handler : function(){ alert(JSON.stringify(projelerTereeRclckMenu.items[0])); },
//iconCls:'icon-grid-del'
},
{
text: 'Saha Oluştur',
handler :
function(){
alert('Sil butonuna tıklandı'); },
name: 'tree-context-saha-olustur',
}
]
});
var projelerTreeStore = Ext.create('Ext.data.TreeStore', {
proxy: {
type: 'ajax',
actionMethods: 'post',
url: 'phps/treeloader.php',
extraParams: {
process:'callNode',
}
},
root: {
text: 'Root Node',
id: '0',
parentid:'0',
expanded: false,
},
folderSort: true,
sorters: [{
property: 'text',
direction: 'ASC'
}]
});
var projelerTree = Ext.create('Ext.tree.Panel',{
store: projelerTreeStore,
id:'projelerTree-id',
renderTo: Ext.getBody(),
height: 300,
width: 250,
title: 'PMT Ağaç Yapısı',
tbar : [{
text:'Yenile',
handler:
function(){
//projelerTree.getView().refresh();
//projelerTree.treeRefresh();
}
},
{
text: 'add node',
handler:
function(){
if (projelerTree.getSelectionModel().hasSelection()) {
var selectedNode = projelerTree.getSelectionModel().getSelection();
Ext.MessageBox.prompt('Add Node', 'Please enter node text:', function(btn, text){
if (btn == 'ok'){
Ext.Ajax.request({
url: 'phps/treeloader.php',
params: {
nodetext: text,
parentid : selectedNode[0].data.id,
depth: selectedNode[0].data.depth,
process: 'addNode'
},
success: function(response){
var id = response.responseText;
if (id > 0){
selectedNode[0].set('leaf', false);
alert('success');
selectedNode[0].appendChild({
leaf: true,
text: text,
id: id,
});
();
}
}
});
}
});
}else{
Ext.MessageBox.alert('Uyarı!', 'Lütfen node eklemek istediğiniz yeri seçiniz!');
}
}//handler
}],
listeners: {
render:
function() {
Ext.getBody().on("contextmenu", Ext.emptyFn, null, {preventDefault: true}
);
},
itemcontextmenu :
function( view, record, item, index, event ){
x = event.browserEvent.clientX;
y = event.browserEvent.clientY;
var selectedNode = projelerTree.getSelectionModel().getSelection();
var depth = selectedNode[0].data.depth;
if(depth==0){
projelerTereeRclckMenu.showAt([x,y]);
}else if(depth ==1){
fazlarTereeRclckMenu.showAt([x,y]);
}else if(depth == 2){
kontratlarTereeRclckMenu.showAt([x,y]);
}else if(depth == 3){
sahalarTereeRclckMenu.showAt([x,y]);
}
},
click: {
element: 'el', //bind to the underlying el property on the panel
fn: function(){ }
},
dblclick: {
element: 'body', //bind to the underlying body property on the panel
fn:
function(){
Ext.getBody().on("contextmenu", Ext.emptyFn, null, {preventDefault: true});
}
},
}
});
var desktop = this.app.getDesktop();
var win = desktop.getWindow('tree-projeler');
if(!win){
var win = desktop.createWindow({
id: 'window-projeler',
listeners:{
beforeshow:function(){
projelerTereeRclckMenu.hide();
}
},
//closeAction: 'destroy',
title:'Projeler',
width:600,
height:400,
iconCls: 'projectManage-shortcut',
animCollapse:false,
border: false,
closeAction: 'hide',
hideMode: 'offsets',
layout: 'fit',
items: [
projelerTree,
]
});
}
return win;
},//Createwindow function ens here
});

Resources