PDA

View Full Version : Delete columns in grid



Poojabk09
10 May 2010, 9:19 PM
I have view port, on center of my Viewport i have grid an on west of my viewport is my tree .. im dragging a node from tree an adding as columns which works totally fine now i hav a problem in deleting them .. i hav put a button on click of this button i wann delete all the columns i hav added by dragging from tree node ... plz help :) code i hav written so far..... dont bother much abt the south region of my view port plz can any1 help its urgent



Ext.onReady(function(){

var view = new Ext.Viewport({
layout:'border',
items:[{
region: 'west',
xtype: 'treepanel',
autoScroll:true,
enableDrag:true,
ddGroup: 'view-group',
loader: new Ext.tree.XmlTreeLoader({
dataUrl:'DTDXML.XML',
requestMethod:'GET',
isFlatXml: true,
PrntIDStore: 'P',
RootPrntID: '0',
NodeIDStore: 'M',
processAttributes:function(attr){
attr.text=attr.LE;
attr.loaded=true;
},
createNode: function(node) {
var attr = {
tagName: node.tagName
};
if(node.attributes.length>0)
Ext.each(node.attributes, function(a) {
attr[a.nodeName] = a.nodeValue;

});
if (this.NodeIDStore.length > 0) {
attr.id = eval("attr." + this.NodeIDStore);
}
this.processAttributes(attr);

return PC.OrchXmlTreeLoader.superclass.createNode.call(this, attr);
}
}),
root: new Ext.tree.AsyncTreeNode({
text: 'Forms',
id:'0'
}),
title:'TreeLoader',
width:250

},
{
region:'center',
xtype:'panel',
autoScroll:true,
items:griddata(),
title:'Grid',
width:500
},
{
region:'south',
xtype:'panel',
title:'Property',
autoScroll:true,
items:propertydata(),
width:500,
height:100
}]
});
});


the function i hav called in my west an center region of my viewport

var grid = new Ext.grid.GridPanel({
store: store1,
id:'gdView',
enableDD:true,
autoScroll:true,
ddGroup : 'view-group',
tbar:[{
text:'DeleteAll',
handler:function(dd, e, data)
{
//var target = Ext.lib.Event.getTarget(e);
//var colIdx = grid.getView().findCellIndex(target);
//var ColMdlIndx= grid.getColumnModel().findColumnIndex(data.node.attributes.text);
//if(ColMdlIndx!=-1)
//{
//return false;

//}
//if(data.node != null)
//{
store1.remove();
//}



// hideHeaders:true
/*var index = grid.getSelectionModel().getSelectedCell();

if (!index)
{
return false;
}
var rec = store.getAt(index[0]);

store.remove(rec);*/
}
}],
columns: [
{header:"attr.text",width:100,hidden:true}
],
renderTo:document.body,
width:730,
height:580,
headerclick:true,
listeners:{
headerclick:function(grid,index,ev){
alert("header index = " + index);
}}

});
var ddropTarget = new Ext.dd.DropTarget(grid.getEl(), {
ddGroup: "view-group",
copy:true,
notifyDrop : function(dd, e, data)
{
var target = Ext.lib.Event.getTarget(e);
var colIdx = grid.getView().findCellIndex(target);
var ColMdlIndx= grid.getColumnModel().findColumnIndex(data.node.attributes.text);
if(ColMdlIndx!=-1){
Ext.Msg.show({
title:'Warning',
msg: 'The column already exists',
buttons: Ext.Msg.OK,
icon: Ext.MessageBox.WARNING
});
return false;
}
if(data.node != null)
{
grid.addColumn({name: data.node.attributes.text, defaultValue: data.node.attributes.text}, {header: data.node.attributes.text, dataIndex: data.node.attributes.text},colIdx);
}
}
});

return grid;
}

propertydata = function()
{
var store = new Ext.data.Store({
url :'property.xml',
reader: new Ext.data.XmlReader({
record:'P',
id:'@NAME'
}, [


{name:'NAME',mapping:'@NAME', type: 'string'},
{name:'V',mapping:'@V',type: 'string'}

])
});

var name_edit = new Ext.form.TextField();
var value_edit = new Ext.form.TextField();
var grid1 = new Ext.grid.EditorGridPanel({
store: store,
id:'propertyid',
clickstoEdit: 1,
hidden:true,
columns:
[
{header: "Name", width: 120, dataIndex: 'NAME',editor:name_edit},
{header: "Value", width: 120, dataIndex: 'V',editor:value_edit}
],
width:200,
height:500

});
store.load();
return grid1;

}

13 May 2010, 4:00 AM
please reformat your post and use CODE or PHP tags