Array to Table


Joined
Oct 18, 2015
Messages
5
Reaction score
0
I am doing the below to create a table....it works sort of but was unable to get this to work with my array converted to JSON. I went back to the variable "data" and I was able to show results....but a very simple table and without field name header
I am not able to figure out how to have table header with field names etc.

Can anyone help or show a better example to get a table...maybe one with sort options....looking for a better table.

JavaScript:
function updateGrid3(featureSet) {
    var data = arrayUtils.map(featureSet.features, function (entry, i) {
      return {
        id: entry.attributes.OBJECTID,
        ObsID: entry.attributes.ObsID,
        SppBova: entry.attributes.SppBova,
        COMMON_NAME: entry.attributes.COMMON_NAME,
        GENUS: entry.attributes.GENUS,
        SPECIES: entry.attributes.SPECIES,
        Tier: entry.attributes.Tier,
        FedStatus: entry.attributes.FedStatus,
        TaxaGrp: entry.attributes.TaxaGrp,
      };
    });


    // If you use a store...
    dataStore = new Memory({
        "data": data,
        "idProperty": "id"
    });

var myJsonString = JSON.stringify(data);
var json_obj = JSON.parse(myJsonString);

var arr = (data);
alert (arr.length);

    var i;
    var out = "<table id=t01>";
    for(i = 0; i < data.length; i++) {
        out += "<tr><td>" +
        arr[i].id +
        "</td><td>" +
        arr[i].ObsID +
        "</td><td>" +
        arr[i].SppBova +
        "</td><td>" +
        arr[i].COMMON_NAME +
        "</td><td>" +
        arr[i].GENUS +
        "</td><td>" +
        arr[i].SPECIES +
        "</td><td>" +
        arr[i].Tier +
        "</td><td>" +
        arr[i].FedStatus +
        "</td><td>" +
        arr[i].TaxaGrp +
        "</td></tr>";
    }
    out += "</table>";
    document.getElementById("id01").innerHTML = out;
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top