Menu

JST Question

2007-06-05
2013-04-22
  • Ivo Baehr - IbTech

    Hello friends!

    I have two doubts about JavaScripTable...
    - First: I Can "customize in run-time" the cell's color?? There are some method that is called in the "onDrawCell" event?? I would like to do something like this: If the cell's value is major then X, the cell color is red, else, the cell color is blue.
    - Second: I Can put a litle image with the text in a cell in the JST? A image like a "face happy or unhappy". at news, this face depends of the "cell's value"

    Thank's for the help friends!!

     
    • Luis Fernando Planella Gonzalez

      Hi!
      The answer to both questions are the same: using custom parsers for those columns.

      var LIMIT = 100;
      function colorize(number) {
          var color = (number > LIMIT) ? "red" : "blue";
          return "<span style='color:" + color + "'>" + number + "</span>";
      }

      function faces(flag) {
          var image = flag ? "happy.gif" : "sad.gif";
          return "<img src='" + image + "'>";
      }

      var numberColumn = table.addColumn(...);
      numberColumn.parser = new CustomParser(colorize);

      var faceColumn = table.addColumn(...);
      faceColumn.parser = new CustomParser(faces);

      On the example, if you would need a number formatting as well, you would have to build a NumberParser and return "<span style='color:" + color + "'>" + myNumberParser.format(number) + "</span>" instaed.

      Hope this helps.

       
      • Ivo Baehr - IbTech

        Thank's for this help Luis!!

        I will try to do this!!!

        bye

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.