views:

42

answers:

2

Clicking on the second cell (any row) in the datatable causes the cell editor to display. But, I am trying to display the cell editor from code. The code looks like the following:

    var firstEl = oDataTable.getFirstTdEl(rowIndex);
    var secondCell = oDataTable.getNextTdEl(firstEl);
    oDataTable.showCellEditor(secondCell);

When I debug into the datatable.js code (either with a click or from the code above) it follows the same path through the showCellEditor function but the above code will not display the editor.

I am using YUI version 2.8.0r4.

A: 

I think this is blur events issue.

So, for example, I have link that must add record to datatable, and show its editor.

var mymethod = function (e) {
  YAHOO.util.Event.stopEvent(e);
  var r = {};
  r.id = 0;
  r.value = 'hello world';

  myDataTable.addRow(r);
  var cell = myDataTable.getLastTrEl().cells[0];
  myDataTable.showCellEditor(cell);        
}

YAHOO.util.Event.addListener('mylink2addrecord_ID', 'click', mymethod);

Without stopEvent you will never see editor, because there is tableBlur event called when you click on yourlink....

mac
A: 

As mac said, you need to stop the previous event. For some reason it (the tableBlur event) conflicts with the showCellEditor function. This is the first place which had a resolution to the problem.

To sum it up, all I did was:

YAHOO.util.Event.stopEvent(window.event);
dt.showCellEditor(td); // dt = yui datatable obj, td = {record: yuirecord, column: yuicolumn}

Of course if you have the event object readily available as mac's post does, you can pass it to stopEvent(e) like he did.