code: def ToJSCode(self, name, columns_order=None, order_by=()):
      encoder = DataTableJSONEncoder()
      if columns_order is None:
        columns_order = [col["id"] for col in self.__columns]
      col_dict = dict([(col["id"], col) for col in self.__columns])
      jscode = "var %s = new google.visualization.DataTable();\n" % name
      if self.custom_properties:
        jscode += "%s.setTableProperties(%s);\n" % (
            name, encoder.encode(self.custom_properties))
      for i, col in enumerate(columns_order):
        jscode += "%s.addColumn(%s, %s, %s);\n" % (
            name,
            encoder.encode(col_dict[col]["type"]),
            encoder.encode(col_dict[col]["label"]),
            encoder.encode(col_dict[col]["id"]))
        if col_dict[col]["custom_properties"]:
          jscode += "%s.setColumnProperties(%d, %s);\n" % (
              name, i, encoder.encode(col_dict[col]["custom_properties"]))
      jscode += "%s.addRows(%d);\n" % (name, len(self.__data))
      for (i, (row, cp)) in enumerate(self._PreparedData(order_by)):
        for (j, col) in enumerate(columns_order):
          if col not in row or row[col] is None:
            continue
          value = self.CoerceValue(row[col], col_dict[col]["type"])
          if isinstance(value, tuple):
            cell_cp = ""
            if len(value) == 3:
              cell_cp = ", %s" % encoder.encode(row[col][2])
            jscode += ("%s.setCell(%d, %d, %s, %s%s);\n" %
                       (name, i, j,
                        self.EscapeForJSCode(encoder, value[0]),
                        self.EscapeForJSCode(encoder, value[1]), cell_cp))
          else:
            jscode += "%s.setCell(%d, %d, %s);\n" % (
                name, i, j, self.EscapeForJSCode(encoder, value))
        if cp:
          jscode += "%s.setRowProperties(%d, %s);\n" % (
              name, i, encoder.encode(cp))
      return jscode