1

My apex controller returns this JSON object with the name of the product:id ( if we have no id is that the product is unvalid.

{
\"SKE-95\":null,
\"RG-9323\":\"a003000000IOGm3AAH\",
\"SDF-5022\":\"a003000000IOGliAAH\",
\"HGT-3531\":\"a003000000IOGldAAH\",
\"DE-5430\":\"a003000000IOGjwAAH\"
}

I'd like to know if it's possible to generate a table with javascript that looks like:


| name | status |

ske-95 | unvalid

sdf-5022| valid

....


2
  • are you using remote action to return above json object?
    – Himanshu
    Nov 25, 2015 at 14:19
  • @Himanshu no I'm using an actionfunction
    – Joey Pablo
    Nov 25, 2015 at 14:26

1 Answer 1

0

The JSON format (assuming the backslashes are not actually present) you have is not ideal because although you can use a for...in loop over those values in JavaScript the ordering will be arbitrary which is probably not what you want. An array of objects would make more sense so you could loop over the elements in index order:

[
    {"SKE-95":null},
    {"RG-9323":"a003000000IOGm3AAH"},
    {"SDF-5022":"a003000000IOGliAAH"},
    {"HGT-3531":"a003000000IOGldAAH"},
    {"DE-5430":"a003000000IOGjwAAH"}
]

You can create arrays/lists and maps in Apex to achieve the ordering you need when you JSON.serialize.

For such a simple table, to create the table in JavaScript you don't need anything more than the raw DOM methods to add the table, table rows and table cells.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .