如何在yui数据表中设置Date Cell Editor的上下文位置

时间:2012-03-12 08:43:56

标签: yui yui-datatable

我想将内联日期单元格编辑器的位置设置为[“tr”,“br”],并引用yui数据表单元格。我怎么能这样做?

这种方式不起作用 - column.editor.cfg.setProperty(“context”,[target,“tr”,“br”])

2 个答案:

答案 0 :(得分:1)

我刚刚覆盖了数据表的doBeforeShowCellEditor方法,并更改了单元格编辑器的上下文位置逻辑。大多数代码都是从YUI basecelleditor的移动函数中复制的。 http://developer.yahoo.com/yui/docs/YAHOO.widget.BaseCellEditor.html

DataTable.doBeforeShowCellEditor = function(cellEditor){
   if(cellEditor.calendar){
      // Move Editor
      var elContainer = cellEditor.getContainerEl(),
      elTd = cellEditor.getTdEl(elContainer),
      x = d.getX(elTd),
      y = d.getY(elTd);
      //TODO: remove scrolling logic
      // SF doesn't get xy for cells in scrolling table
      // when tbody display is set to block
      if(isNaN(x) || isNaN(y)) {
        var elTbody = this.getTbodyEl();
        x = elTd.offsetLeft + // cell pos relative to table
          d.getX(elTbody.parentNode) - // plus table pos relative to document
          elTbody.scrollLeft; // minus tbody scroll
        y = elTd.offsetTop + // cell pos relative to table
          d.getY(elTbody.parentNode) - // plus table pos relative to document
          elTbody.scrollTop + // minus tbody scroll
          this.getTheadEl().offsetHeight; // account for fixed THEAD cells
      }
      cellEditor.show();
      //alert(x + " : X : width : " + elContainer.offsetWidth);
      x = x - elContainer.offsetWidth + elTd.offsetWidth;
      //alert(x + " : X");
      elContainer.style.left = x + "px";
      elContainer.style.top = y + "px";          
    }
    return true;
  };

答案 1 :(得分:0)

我知道我迟到了,但我喜欢完整......

使用Dheeraj Kumar Aggarwal代码作为起点,我做了一些改进,包括定义" d"。下面的代码只会重新定位单元格编辑器,如果它从水平或垂直(或两者)下降到屏幕边缘。

objDataTable.doBeforeShowCellEditor = function(cellEditor){
    if(cellEditor.calendar){
        // Move Editor
        var d = YAHOO.util.Dom,
            elContainer = cellEditor.getContainerEl(),
            elTd = cellEditor.getTdEl(elContainer),
            x = d.getX(elTd),
            y = d.getY(elTd);
            numWindowWidth = d.getDocumentWidth();    /// The size of the browser frame
            numWindowHeight = d.getDocumentHeight();  /// The size of the browser frame
        //TODO: remove scrolling logic
        // SF doesn't get xy for cells in scrolling table
        // when tbody display is set to block
        if(isNaN(x) || isNaN(y)) {
            // console.log('this.getTbodyEl()',this.getTbodyEl(),'this',this);
            var elTbody = this.getTbodyEl();
            x = elTd.offsetLeft + // cell pos relative to table
                d.getX(elTbody.parentNode) - // plus table pos relative to document
                elTbody.scrollLeft; // minus tbody scroll
            y = elTd.offsetTop + // cell pos relative to table
                d.getY(elTbody.parentNode) - // plus table pos relative to document
                elTbody.scrollTop + // minus tbody scroll
                this.getTheadEl().offsetHeight; // account for fixed THEAD cells
        }
        cellEditor.show();
        //alert(x + " : X : width : " + elContainer.offsetWidth);
        if (x + elContainer.offsetWidth > numWindowWidth) {
            x = x - elContainer.offsetWidth + elTd.offsetWidth;
        }
        if (y + elContainer.offsetHeight > numWindowHeight) {
            y = y - elContainer.offsetHeight + elTd.offsetHeight;
        }
        //alert(x + " : X");
        elContainer.style.left = x + 'px';
        elContainer.style.top = y + 'px';
        // console.log('x',x,'y',y,'elContainer',elContainer);
    }
    return true;
};