PDA

View Full Version : Update a node name, made dirty the next node in TreeGrid



MexRus
30 Sep 2011, 12:02 AM
I made a CRUD action to a TreeStore as the Ext.data.writer.Writer example.
Add and Delete functions works OK, but Updating the name of the node, made the node dirty, after that I do a sync, the node its ok, but the next node get the same index as the node update, then made it dirty!!

I can't find where ti fix this problem

28425
28426
28427
POST:

{"data":{"id":18,"name_file":"Friends NEW","count_file":0,"parentId":"0","index":1,"depth":1,"checked":null}}
RESPONSE:

{"success":true,"message":"Update record","data":{"id": 18,"cls": "folder", "index":1,"count_file":"0", "depth":1, "parentId": "0","name_file":"Friends NEW"}}




Ext.define('Tree_Folders', {
extend: 'Ext.data.Model',
fields: [
'id',
{name: 'name_file', type: 'string'},
{name: 'count_file', type: 'int'}
]
});

var store_treefolders = Ext.create('Ext.data.TreeStore', {
model: 'Tree_Folders',
autoLoad: true,
autoSync: true,
defaultProxyType: 'ajax',
proxy: {
batchActions: false,
type: 'ajax',
api: {
create: '/app/tree_folder_test.json.php?action=create&',
read: '/app/tree_folder_test.json.php',
update: '/app/tree_folder_test.json.php?action=update&',
destroy: '/app/tree_folder_test.json.php?action=destroy&',
},
reader: {
type: 'json',
root: 'data',
messageProperty: 'message'
},
writer: {
type: 'json',
writeAllFields: true,
root: 'data',

},
},

root: {
id: "0",
name_file: 'root_1',
expanded: true
}

});

var tree_files = Ext.create('Ext.tree.Panel', {
title: 'Folders & files',
id: 'tree_files',
width: 250,
height: 350,
rootVisible: true, // for test
store: store_treefolders,
multiSelect: false,
singleExpand: true,
bbar: [
{
text: 'Edit folder',
handler: function(){
var selectedNode = tree_files.selModel.selected.items[0];
if(selectedNode)
{
Ext.Msg.prompt('Edit', 'Folder name:', function(btn, text){
if (btn == 'ok' && text.length >0 ){
if(selectedNode.get('name_file') != text){
tree_files.store.getRootNode( ).getChildAt( selectedNode.data.index ).set('name_file', text);
// got ditry!!
tree_files.store.sync();
// the next node got DIRTY! with index-1
}

}

}, this, false, selectedNode.get('name_file'));
}
else{
Ext.Msg.alert('Attention', 'Select first a node!.');
}
}
}],


columns: [{
xtype: 'treecolumn', //this is so we know which column will show the tree
text: 'Folder',
dataIndex: 'name_file'
},{
text: 'Count',
dataIndex: 'count_file'
}

]
});



Some code was ripped out to simpicity porpouse.

28430

MexRus
4 Oct 2011, 2:36 AM
Also I try some different without result, after sync, the next NODE appear as dirty, and change the INDEX value,


var node =tree_files.store.getNodeById(a.getId());
node.set('name_file', text);


Help me please, I spend 2 weeks without result!

redraid
4 Oct 2011, 5:45 AM
In selModel we already have selected records, try this:

handler: function() {
var me = this,
selectedNode = tree_files.selModel.getSelection()[0],
fileName;

if(selectedNode) {
fileName = selectedNode.get('name_file');
Ext.Msg.prompt('Edit', 'Folder name:', function(btn, text) {
if (btn == 'ok' && text.length > 0) {
if(fileName != text) {
selectedNode.set('name_file', text);
tree_files.store.sync();
}
}
}, me, false, fileName);
}
else {
// handle selectionchange event and enable/disable button(s)
Ext.Msg.alert('Attention', 'Select first a node!.');
}
}

MexRus
5 Oct 2011, 4:15 AM
I trying the code, thanks!
but after the 3th node name change (different) send to the server 3 response
actions:
1) change node's node 3
send update to the server node 3
2) change name's node 2
send update to the server node 2
3) change name's node 1 (the first node is 0)
send update to the server node 1 and
send node the previous updated node (this case 2),
and repeated the point 3


Problem is the index parameter I don't know why its changed.

I'm busy, today I'll check but your contribution help me.

Thanks a lot

???????? ??? ???????!
????? ????? ??? ??????. ???? ???????????.