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

Re: Passing dynamic data to a datatable formatter?

Expand Messages
  • htrla57
    I think I found a solution to my problem, which was to pass context dependent data to a datatable formatter (I am handling a variable number of datatables with
    Message 1 of 7 , Jul 3, 2009
      I think I found a solution to my problem, which was to pass context dependent data to a datatable formatter (I am handling a variable number of datatables with a single set of functions, and there is need for the formatter to be aware of the context).

      The trick was to define the formatter separately for each datatable, like this:

      tbl = new YAHOO.widget.DataTable(tblel, coldefs, ds) ;
      var col = tbl.getColumn("deadline") ;
      col.formatter = function(el, oR, oC, oD) { tdFormatter(el, oR, oD, ctx, tid) ; } ;
      tbl.render() ;

      Now the formatter function gets the correct values of ctx and tid in each datatable instance. In my original approach I had overlooked how closures work in Javascript, and ended up with incorrect values in the formatter.

      There may still be a better way, though.
    Your message has been successfully submitted and would be delivered to recipients shortly.