PDA

View Full Version : grid.getSelectionModel().getSelectedCell is not a function when sm is in grid config



Aero
20 Jul 2010, 2:43 PM
Hi again,

I know this topic have been discussed before,but i cant get it to work. Insert a new row at a specific rowIndex on a editorgrid. Apprently the selectionModel is different between grid and editorgrid when it comes to getters for row and cells?

Well, i have tried everything. The things is, it works when i dont use a sm config in my gid.Adding it and it stops working by just saying getSelectedCell is not a function.

So i thought to just include the rowIndex param on cellcontextmenu and then pass it to InsertNewItem(rowIndex) function but this function fires directly on the grids cellcontextmenu/right click ? How is that possible,i defined a handle in the menu.



var gridh = new Ext.grid.EditorGridPanel({
..
..
..
listeners : {

cellcontextmenu:CtxMenu,

}
})


var CtxMenu = function(myEditorGrid, rowIndex, cellIndex, eObj) {
evtObj.stopEvent();
editorGrid.rowCtxMenu = new Ext.menu.Menu({
items : [
{
text : 'Insert New Record',
handler : insertNewItem(rowIndex)
},
{
text : 'Delete Record'
}
]
});
editorGrid.rowCtxMenu.showAt(evtObj.getXY());
}


var insertNewItem = function(rowId) {
var newRecord = new remoteJsonStore.recordType({
newRecordId : Ext.id()
});

remoteJsonStore.insert(rowId, newRecord);
grid.startEditing(selectedRowIndex,0);
}



So,back to the selecModel,why does it not work in the insertNewItem function with



var selectedCell = grid.getSelectionModel().getSelectedCell();
var selectedRowIndex = selectedCell[0];
remoteJsonStore.insert(selectedRowIndex, newRecord);
grid.startEditing(selectedRowIndex,0);


or



var sm = grid.getSelectionModel()
var selectedRowIndex = sm.getSelections()
remoteJsonStore.insert(selectedRowIndex, newRecord);
grid.startEditing(selectedRowIndex,0);


Any tips on this ?

Thanks!

Animal
20 Jul 2010, 9:33 PM
Did you configure it with CellSelectionModel?

Aero
21 Jul 2010, 12:27 AM
Animal,

Thank you.No i didn't i used the CellModell, it was RowSelectionModel but i switched to Cell and now insertNewItem function works. However now my dnd is dead,not even dragtext is working. It keeps firing "c.isSelected is not a function".

Animal
21 Jul 2010, 12:33 AM
Debug.

Aero
21 Jul 2010, 2:09 AM
Yeah, i did just to find out that cellSelectionModel does not have any isSelected method and DnD function out-of the box. But user izhaki overrided the dragzone by:



Ext.override(Ext.grid.GridPanel, {
getDragDropText : function(){
var count;

var sm = this.selModel;

if (sm instanceof Ext.grid.RowSelectionModel)
count = sm.getCount();
if (sm instanceof Ext.grid.CellSelectionModel)
count = 1;
return String.format(this.ddText, count, count == 1 ? '' : 's');
},
});

Ext.override(Ext.grid.GridDragZone, {

getDragData : function(e){
var t = Ext.lib.Event.getTarget(e);
var rowIndex = this.view.findRowIndex(t);
var cellIndex = this.view.findCellIndex(t);

if(rowIndex !== false){
var sm = this.grid.selModel;

// RowSelectionModel
if (sm instanceof Ext.grid.RowSelectionModel)
{
if(!sm.isSelected(rowIndex) || e.hasModifier()){
sm.handleMouseDown(this.grid, rowIndex, e);
}
return {grid: this.grid, ddel: this.ddel, rowIndex: rowIndex, selections:sm.getSelections()};
}

// CellSelectionModel
if (sm instanceof Ext.grid.CellSelectionModel)
{
sel = sm.getSelectedCell();

rowAlreadySelected = sel && sel[0] == rowIndex;

if(!rowAlreadySelected || e.hasModifier()){
sm.handleMouseDown(this.grid, rowIndex, cellIndex, e);
}

store = this.grid.getStore();
sel = sm.getSelectedCell();
if (sel)
return {grid: this.grid, ddel: this.ddel, rowIndex: rowIndex, selections: [store.getAt(sel[0])]};
else
return {grid: this.grid, ddel: this.ddel, rowIndex: rowIndex, selections: []};
}
}
return false;
},

});
This "works",but i can still not insert any record on drop becuase i can't get the row selections
Now looking at the api there are many mouseUp or event that fires upon dragComplete in the drafzone,can the code above help me insert the dragged row ?

Animal
21 Jul 2010, 2:34 AM
Well you can get the Record underlying the row mousedowned on!

http://www.sencha.com/deploy/dev/docs/?class=Ext.grid.GridView&member=findRowIndex

And you already know about store.getAt(rowIndex)

Aero
21 Jul 2010, 5:21 AM
Animal,

Again,thank you. I did just that and ended up with a event in the DragZone.



afterDragDrop: function(dd,e,id) {


var sm = Ext.getCmp('gridh').getSelectionModel()
var rows = store.getAt(sel[0]);
var t = Ext.lib.Event.getTarget(e);
var rowIndex = this.view.findRowIndex(t);

var cindex = rowIndex;
remoteJsonStore.remove(remoteJsonStore.getById(rows.id));
remoteJsonStore.insert(cindex,rows);

},



It works for one record/row,dont know if multiple records can be implemted.If looking more sm.hasSelection() and looping over the insert/remove rows it can might be done,if cellModel allow the sm to have multiple selection.