Loading ...
Sorry, an error occurred while loading the content.
 

Re: disabling table rows and cells

Expand Messages
  • Pete Gontier
    And you ll need one more line: YAHOO.lang.extend (DataTableCanDisableElements, YAHOO.widget.DataTable); ... intended to
    Message 1 of 4 , Aug 3, 2008
      And you'll need one more line:

      YAHOO.lang.extend (DataTableCanDisableElements, YAHOO.widget.DataTable);


      --- In ydn-javascript@yahoogroups.com, "Pete Gontier" <pete@...> wrote:
      >
      > I poked around in the data table sources and came up with some ideas
      > to deal with the way it re-renders the HTML whenever the sorting
      > changes. This is by no means the final answer to this question, but
      > we're getting there.
      >
      >
      >
      > DataTableCanDisableElements = function
      > (elContainer,aColumnDefs,oDataSource,oConfigs)
      > {
      > this.disableCellElement = function (cell)
      > {
      > YAHOO.util.Assert.areSame ('TD', cell.tagName);
      > if (cell.getElementsByClassName
      > (YAHOO.widget.DataTable.CLASS_DISABLED).length) return;
      > var cellChild = cell.firstChild;
      >
      > while (cellChild)
      > {
      > YAHOO.util.Dom.addClass (cellChild,
      > YAHOO.widget.DataTable.CLASS_DISABLED);
      > cellChild = cellChild.nextSibling;
      > }
      > }
      >
      > this.disableRowElement = function (row)
      > {
      > YAHOO.util.Assert.areSame ('TR', row.tagName);
      > if (row.getElementsByClassName
      > (YAHOO.widget.DataTable.CLASS_DISABLED).length) return;
      > var rowChild = row.firstChild;
      >
      > while (rowChild)
      > {
      > this.disableCellElement (rowChild);
      > rowChild = rowChild.nextSibling;
      > }
      > }
      >
      > this.disableRow = function (row)
      > {
      > this._aDisabled [this._aDisabled.length] = row.getId ( );
      > this.disableRowElement (this.getTrEl (row));
      > }
      >
      > this.disableAfterRender = function ( )
      > {
      > var theDisabled = this._aDisabled;
      >
      > for (var index in theDisabled)
      > {
      > if (YAHOO.lang.isString (theDisabled [index])) // it's a row ID
      > {
      > this.disableRowElement (this.getTrEl (this.getRecord (theDisabled
      > [index])));
      > }
      > else // we assume it's a cell
      > {
      > }
      > }
      > }
      >
      > this._aDisabled = [ ];
      > DataTableCanDisableElements.superclass.constructor.call
      > (this,elContainer,aColumnDefs,oDataSource,oConfigs);
      > this.addListener ('renderEvent', this.disableAfterRender);
      > }
      >
      >
      >
      > --- In ydn-javascript@yahoogroups.com, "Pete Gontier" <pete@> wrote:
      > >
      > > As soon as I posted this, I made one of my table's columns sortable
      > > and discovered that sorting it blows away the "yui-dt-disabled" class.
      > > Disappointing. I'll have to look into what I can do about this.
      > >
      > > --- In ydn-javascript@yahoogroups.com, "Pete Gontier" <pete@> wrote:
      > > >
      > > > It took me a fair amount of time to figure out that
      > > > YAHOO.widget.DataTable.CLASS_DISABLED (AKA yui-dt-disabled) isn't
      > > > actually used anywhere in YUI. The name gets defined, but nobody
      > > > assigns it to any elements and nobody defines a style for it. (Why
      > > > grep didn't occur to me sooner is a mystery.) It also took me a fair
      > > > amount of time to decide what the do about this, so I figured I'd
      > > > share what I came up with.
      > > >
      > > > Here's the CSS I'm using. You are of course free to use anything you
      > > like.
      > > >
      > > > .yui-dt-disabled
      > > > {
      > > > opacity : 0.25;
      > > > }
      > > >
      > > > It may be that this CSS could be optimized quite nicely by a CSS
      > > > wizard to do what the JavaScript below does. That would be way cool
      > > > because then we could just slap the class on the row and the browser
      > > > would reach down into the cells and make them less opaque and that
      > > > would be a lot faster.
      > > >
      > > > And here is the JavaScript I'm using (so far). This isn't
      intended to
      > > > be a definitive answer but a jumping-off point.
      > > >
      > > > function DisableTableCell (cellElement)
      > > > {
      > > > YAHOO.util.Assert.areSame ('TD', cellElement.tagName);
      > > > if (cellElement.getElementsByClassName
      > > > (YAHOO.widget.DataTable.CLASS_DISABLED).length) return;
      > > > var cellChild = cellElement.firstChild;
      > > >
      > > > while (cellChild)
      > > > {
      > > > var yCellChild = new YAHOO.util.Element (cellChild);
      > > > yCellChild.addClass (YAHOO.widget.DataTable.CLASS_DISABLED);
      > > > cellChild = cellChild.nextSibling;
      > > > }
      > > > }
      > > >
      > > > function DisableTableRow (rowElement)
      > > > {
      > > > YAHOO.util.Assert.areSame ('TR', rowElement.tagName);
      > > > if (rowElement.getElementsByClassName
      > > > (YAHOO.widget.DataTable.CLASS_DISABLED).length) return;
      > > > var rowChild = rowElement.firstChild;
      > > >
      > > > while (rowChild)
      > > > {
      > > > DisableTableCell (rowChild);
      > > > rowChild = rowChild.nextSibling;
      > > > }
      > > > }
      > > >
      > > > And finally here is what my click listener looks like:
      > > >
      > > > dataTable.SelectRow = function (oArgs)
      > > > {
      > > > if (oArgs.target.getElementsByClassName
      > > > (YAHOO.widget.DataTable.CLASS_DISABLED).length) return;
      > > > this.onEventSelectRow (oArgs);
      > > >
      > > > }
      > > >
      > > > Hope this helps...
      > > >
      > >
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.