PDA

View Full Version : Mixing Selection and Edit mode



DionVerbeke
13 Oct 2006, 2:16 AM
Hi,

In the new grid I'd like to mix Selection Mode and Edit mode, i.e. I like to select certain rows for further rows, but at the same time allow the client to change certain cells.

Is this possible?

Kind Regards,

Dion

jack.slocum
13 Oct 2006, 5:42 AM
Selection mode has 1 set of keyboard navigation, editor has another. They both conflict. But, if you don't mind disabling editing keyboard navigation, you could probably hack up the editor selection model. Since single click would select a row, you'd have to use double click for edit. This is completely untested, but I don't see why it wouldn't work:



YAHOO.ext.grid.EditorAndSelectionModel = function(){
YAHOO.ext.grid.EditorAndSelectionModel .superclass.constructor.call(this);
this.events['cellactivate'] = new YAHOO.util.CustomEvent('cellactivate');
};

YAHOO.extendX(YAHOO.ext.grid.EditorAndSelectionModel, YAHOO.ext.grid.DefaultSelectionModel);

YAHOO.ext.grid.EditorAndSelectionModel.prototype.initEvents = function(){
this.grid.addListener("celldblclick", this.onCellDblClick, this, true);
};

YAHOO.ext.grid.EditorAndSelectionModel.prototype.onCellDblClick = function(grid, rowIndex, colIndex){
var row = this.grid.getRow(rowIndex);
var cell = row.childNodes[colIndex];
if(cell){
this.fireEvent('cellactivate', this, row, cell);
this.grid.doEdit(row, cell);
}
};


Then, instead of of creating an EditorGrid, you'd jsut create standard grid and pass in this new EditorAndSelectionModel. You would also have to manually add the class name "yeditgrid" to your grid container element.



var sm = new YAHOO.ext.grid.EditorAndSelectionModel();
var grid = new YAHOO.ext.grid.Grid('containerId', dataModel, colModel, sm);


Let me know if it works.

DionVerbeke
13 Oct 2006, 6:06 AM
Hi Jack,

A little bit better, the selection is now visible for the first row. However, it doesn't allow me to change the selection to other rows in the grid. Which makes it useless for our purposes. (The editing part still works wonderfully though).

Can you give a slight hint where to look for the behaviour of the selection-rows?

Best Regards,

Dion

jack.slocum
13 Oct 2006, 6:43 AM
I didn't make the superclass call to initialize events. Here's the updated initEvents() method:



YAHOO.ext.grid.EditorAndSelectionModel.prototype.initEvents = function(){
YAHOO.ext.grid.EditorAndSelectionModel.superclass.initEvents.call(this);
this.grid.addListener("celldblclick", this.onCellDblClick, this, true);
};

DionVerbeke
13 Oct 2006, 7:46 AM
Big thanks Jack,

It now works as it should be! Can be a great addition for the next release?

Arigatou gozaimashita,

Dion

jack.slocum
13 Oct 2006, 7:57 AM
I don't see why not :)

DionVerbeke
13 Oct 2006, 8:00 AM
One small comment

After the editing is done on a cell, the textbox stays open. You have to change your selection to another row for it to become stabilised. Is this normal?

Thanks,

Dion

jack.slocum
13 Oct 2006, 8:03 AM
What do you mean by "when editing is done". Did you hit enter or move the focus somewhere else?

JasonMichael
20 Feb 2007, 8:00 PM
Would the above code still work? I'm having the same problem with the edit grid. I may just have to post my code to get this straightened out, but I just have been having odd errors trying to implement this functionality.

Jason

JasonMichael
20 Feb 2007, 9:18 PM
Disregard - this newbie just had to get the code setup correctly. The above works GREAT!!!!! THANKS SO MUCH JACK!

-Jason