This worked for me, I was doing basically the same thing with my own <table> block.

In addition to the sorting, I combined the slightly-modified code Neil Ireson provided recently (thanks!) with David's advice on overriding the formatText() method to get a nice thousand-seperator formatted numbers in my table, nicely sortable by numeric value ( see attached screenshot). See code below if someone wants to do the same sort of thing. But I think this should really be in Exhibit itself, given that the number format already has a decimal-digits setting (http:// simile.mit.edu/wiki/Exhibit/2.0/Formats#number). Something like number { thousand-seperator: true} wouldn't look out of place :) . And if it would work in facets as well as lenses/views, that'd be awesome!



Attachment: Picture 3.pdf
Description: application/applefile

Attachment: Picture 3.pdf
Description: Adobe PDF document




 <script type="text/javascript">

    Exhibit.Formatter._NumberFormatter.prototype.formatText =
    function(value) {
      var number;
      if (this._decimalDigits == -1) {
        number = value.toString();
      }
      else {
        number = new Number(value).toFixed(this._decimalDigits);
      }
      number = addCommas(number);
      return number;
    };

function addCommas(nStr)
{
  nStr += '';
  x = nStr.split('.');
  x1 = x[0];
  x2 = x.length > 1 ? '.' + x[1] : '';
  var rgx = /(\d+)(\d{3})/g;
  while (rgx.test(x1)) {
    x1 = x1.replace(rgx, '$1' + ',' + '$2');
  }
  return x1 + x2;
}                                                       

  </script>

On 12 Feb 2008, at 14:37, David Huynh wrote:

Yee-Ting Li wrote:
Hi David,

thanks for the reply :)

it appears to work :) i defined an invisible table within the
ex:role="view" div and the substitution of (A) into column (B).
however, i still have a couple of issues:

- i'm pretty sure that column (B) is a valid number. however, sorting
does not appear to be numeric but alphanumeric :(

Try declaring the value type for that property in your data file, e.g.,

    {
       items: [
          ...
       ],
       properties: {
          "price": {
             valueType: "number"
          }
       }
    }


- what is the difference between ex:formats and ex:columnFormats?
which should i use? if i define this invisible table, the contents of
ex:columnFormats appear to be ignored :( given the above, how do i
specify the format of the column?

If you define that table, then use ex:formats and define the value types
for the properties (see above).

    <div ex:role="view" ex:viewClass="Tabular" ...>
       <table>
          <tr>
             <td ex:formats="number { decimal-digits: 2 }">
                Only <span ex:content=".price"></span>!!!
             </td>
             ...
          </tr>
       </table>
    </div>

I haven't tested that case, so let me know if it works for you.

David

_______________________________________________
General mailing list
[email protected]
http://simile.mit.edu/mailman/listinfo/general

_______________________________________________
General mailing list
[email protected]
http://simile.mit.edu/mailman/listinfo/general

Reply via email to