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

Re: Support for scope in column formatter

Expand Messages
  • lou_tribal
    I am not sure I understand correctly why we should pass the datatable itself as an argument. In my case the datatable object is embedded as a field of another
    Message 1 of 3 , Feb 1, 2008
    • 0 Attachment
      I am not sure I understand correctly why we should pass the datatable
      itself as an argument.

      In my case the datatable object is embedded as a field of another
      object that extends YAHOO.util.Element (lets call it MyElementObject).

      When my customer formatter is called I needed to use the
      MyElementObject as the scope of the formatter to be able to use some
      members and methods from this MyElementObject.

      I did the following change to the Datatable class (starting line 4483):

      var fnFormatter, fScope=this;
      if(YAHOO.lang.isString(oColumn.formatter)) {
      [...]
      } else if(YAHOO.lang.isFunction(oColumn.formatter)) {
      [...]
      } else if(YAHOO.lang.isObject(oColumn.formatter)) {
      fnFormatter = oColumn.formatter.fn;
      fScope = oColumn.formatter.scope || this;
      }
      if(fnFormatter) {
      fnFormatter.call(fScope, elCell, oRecord, oColumn, oData);
      }

      So in fact the scope is 'this' by default or the one that is specified.
      I do not need to pass the datatable itself and everything is working fine.
      May you clarify what you were thinking for my own education? :)
      Thank you Satyam

      <





      --- In ydn-javascript@yahoogroups.com, "Satyam" <satyam@...> wrote:
      >
      > Though they are defined as functions instead of instance methods,
      the scope
      > of the formatter is set to the current instance of the DataTable
      itself just
      > as if it actually was a method. This was meant to make it easy on the
      > developer when defining a custom one while at the same time allowing
      it to
      > work almost like an actual instance method. So, 'this' is already
      in use.
      > If you were to allow for different scopes then you would have to
      pass the
      > DataTable itself as an argument, complicating matters to most users.
      >
      > Satyam
      >
      >
      >
      > ----- Original Message -----
      > From: "lou_tribal" <lou_tribal@...>
      > To: <ydn-javascript@yahoogroups.com>
      > Sent: Friday, February 01, 2008 3:34 PM
      > Subject: [ydn-javascript] Support for scope in column formatter
      >
      >
      > > Hello,
      > > I have a question about column formatter for datatable.
      > > Currently the column formatter are defined as simple functions. The
      > > question is why to not support the callback object like
      > > {fn:myFormatter, scope:myScope}?
      > > This would be very useful in some situation.
      > > I modified the datatable code to support it for my own needs and it is
      > > only a matter of few lines to add and modify.
      > > What do you think about that?
      > >
      > > <
      > >
      > >
      > >
      > >
      > > Yahoo! Groups Links
      > >
      > >
      > >
      > >
      > >
      > > --
      > > No virus found in this incoming message.
      > > Checked by AVG Free Edition.
      > > Version: 7.5.516 / Virus Database: 269.19.18/1254 - Release Date:
      > > 31/01/2008 20:30
      > >
      > >
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.