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

Re: [ydn-javascript] overriding functions in DataTable not working

Expand Messages
  • Satyam
    This wouldn t work and you wouldn t do it this way anyhow. The method onEventSelectRow is an instance method, it is declared as:
    Message 1 of 3 , Dec 3, 2007
    • 0 Attachment
      This wouldn't work and you wouldn't do it this way anyhow.

      The method onEventSelectRow is an instance method, it is declared as:


      The prototype keyword there makes a whole lot of difference, it is what
      makes your instance of DataTable able to inherit that method, otherwise it
      would only be a static method, like Math.abs or such, which are always
      static class methods, not instance ones. But you still don't want to do
      this, because this would affect all instances of DataTable you create. You
      might want to just override it in your instance of DataTable. Then, after
      creating your DataTable, you would redefine it on that one:

      myDataTable.onEventSelectRow = function(ev) .....

      That way you leave the definition of the DataTable alone and override this
      method just in this instance. You don't use 'prototype' here, since this is
      no prototype at all but the end product.

      Anyway, this is not how you would do it. When you subscribe to the event,
      instead of attaching onEventSelectRow, attach it your own function named
      whatever you want, or not named at all:

      myDataTable.subscribe("rowClickEvent", function(ev) {
      var target = YAHOO.util.Event.getTarget(ev);
      var dataIndex = this.getRecordIndex(target);

      Finally, some comments on this code.

      Variables that you don't declare become globals. In your code, target and
      dataIndex would have turned into global variables, not local ones to the
      function as, perhaps, you expected. Declaring them within the function
      (with the var keyword as I did above) makes them local. Second, always put
      your semicolons at the end of statements, in some rare circumstances the
      JavaScript interpreter might get it wrong. Third, always use the second
      argument in parseInt, the base. If you don't, parseInt will try to guess
      the base from the value to parse and if someone entered, say, a month as 08,
      parseInt will fail since a starting zero makes it assume it is octal. And,
      just as a convenience, within the event listener, the scope is set to the
      object that fires the event so, within the event listener, you can use
      'this' instead of myDataTable.

      But, the most important thing is that the second alert won't give you any
      data. The DataSource only fetches the data from whatever source and then it
      passes it to the DataTable and forgets about it. You don't look for data in
      the DataSource because it won't be there, it will be in the DataTable

      myDataTable.subscribe("rowClickEvent", function(ev) {
      var target = YAHOO.util.Event.getTarget(ev);
      var record = this.getRecord(target);

      You might want to read the following articles starting with:


      in the YUI blog. In the end they will save you from a lot of trouble.


      ----- Original Message -----
      From: "Ryan V. Bayona" <r2b2_ry@...>
      To: <ydn-javascript@yahoogroups.com>
      Sent: Monday, December 03, 2007 8:25 AM
      Subject: [ydn-javascript] overriding functions in DataTable not working

      >i have this snippet and its not working for me
      > var myDataTable = new
      > YAHOO.widget.DataTable("myContainer",myColumnDefs,myDataSource,{scrollable:
      > true}) ;
      > myDataTable.subscribe("rowMouseoverEvent",
      > myDataTable.onEventHighlightRow);
      > myDataTable.subscribe("rowMouseoutEvent",
      > myDataTable.onEventUnhighlightRow);
      > myDataTable.subscribe("rowClickEvent", myDataTable.onEventSelectRow);
      > //override
      > YAHOO.widget.DataTable.onEventSelectRow = function(ev)
      > {
      > target = YAHOO.util.Event.getTarget(ev);
      > alert(target)
      > dataIndex = myDataTable.getRecordIndex(target);
      > alert(dataIndex)
      > alert(myDataSource.liveData[parseInt(dataIndex)].information)
      > }
      > its not even doing the alert thing.. am i doing this properly?
      > Yahoo! Groups Links
      > --
      > No virus found in this incoming message.
      > Checked by AVG Free Edition.
      > Version: 7.5.503 / Virus Database: 269.16.13/1165 - Release Date:
      > 02/12/2007 20:34
    • Ryan V. Bayona
      wow,wow,wow! thanks for the tips satyam.. forgive me for being a total noob :) anyway, i changed the code and it now worked:
      Message 2 of 3 , Dec 3, 2007
      • 0 Attachment
        wow,wow,wow! thanks for the tips satyam.. forgive me for being a total
        noob :) anyway, i changed the code and it now worked:

        YAHOO.util.Event.addListener(window, "load", function() {
        YAHOO.example.data = json;
        this.myDataSource = new YAHOO.util.DataSource(YAHOO.example.data)
        this.myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
        this.myDataSource.responseSchema = {
        fields : ["trackerid","username","modify_date","information"]
        //column definition
        this.myColumnDefs = [

        {key : "username",label: "User"},
        {key : "modify_date",label : "Modify Date",sortable:true },
        {key : "information",label : "Information"}

        this.myDataTable = new
        true, selectionMode:"single"}) ;

        this.myDataTable.subscribe("rowClickEvent",function (ev){
        this.target = YAHOO.util.Event.getTarget(ev);
        this.record = this.getRecord(this.target);

        THANKS !
      Your message has been successfully submitted and would be delivered to recipients shortly.