Domanda

I'm trying to create a data table that shows images in the status column. I followed some examples from stackoverflow but it doesn't work. Does anyone know how to get the image to load in the column? The code below works but it doesn't seem like fomatter function is doing anything.

<script src ="http://yui.yahooapis.com/3.13.0/build/yui/yui-min.js"></script>
<script>
   (function() {
       YUI().use("datatable-sort", function(Y) {
          var cols = [
              {key: "Status", label: "Health Status", 
                  formatter: function(el, oRecord, oColumn, oData) {
                     if (oData){
                        el.innerHTML = '<img src="info.png">';
                     }
                  },
                       sortable: true},
              {key: "Company", label: "Issue", sortable: true},
              {key: "Phone", label: "Contact"},
              {key: "Contact", label: "Name", sortable: true}
          ],

          data = [
             {Status: "123", Company: "Company Bee", Phone: "415-555-1234", Contact: "Sally Spencer"},
             {Status: "123", Company: "Acme Company", Phone: "650-555-4444", Contact: "John Jones"},
             {Status: "123", Company: "Industrial Industries", Phone: "408-555-5678", Contact: "Robin Smith"}
          ],
          table = new Y.DataTable({
              columns: cols,
              data: data,
              summary: "Contacts list",
              caption: ""
          }).render("#sort");

         });

       })();
   </script>
È stato utile?

Soluzione

instead of doing what I did, do the following:

{key: "Status", label: "Health Status", formatter:"<img src='{value}' >", allowHTML: true},...

It worked out!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top