1

I want to make a Javascript table which is built with JSON. This JSON is sent from the backend ( using Django ) so it can be changed anytime. Name of the column would be the category. My JSON form looks like:

var data = [
{
    "title": "Leadership",
    "category": "humaninteraction"
},
{
    "title": "Maintenance procedures",
    "category": "procedures"
},
{
    "title": "Situational Awareness",
    "category": "environmentsituations"
},
{
    "title": "Self-Criticism",
    "category": "self"
},
{
    "title": "Tools",
    "category": "aircraft"
}]; 
2
  • Show us what you have tried till now Commented Apr 26, 2016 at 20:11
  • Try jQGrid or Dhtmlx If you are looking for a framework, else you can iterate and build something on your own Commented Apr 26, 2016 at 20:11

1 Answer 1

2

You can use $.getJSON() to get that JSON from the backend and use $.each() to build each row. Like this:

function generateTable(){    
    var rows = '';
    $.getJSON( "backend/method", function( data ) {
      $.each( data, function( key, val ) {
        rows += '<tr>';
        rows += '<td>' + data.title + '</td>';
        rows += '<td>' + data.category+ '</td>';
        rows += '</tr>';
      });
    });
    $('#tableId').append(rows);
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.