Filling a Big Table Rows from JSON Data

CuriousDev

I am trying to fill up a table using JSON data

Here's what I am thinking

$.ajax({
  dataType: "json",
  url: "music.json"
})
.done(function(gamesjson){
    DATA = gamesjson;
    buildTable(DATA ); // this one is calling the above code
  })
.fail(function(){
    console.log("music.json error");
  })
;

function buildTable(DATA){
var gl = $("#gl");
$.each(DATA.music, function(index, value) {
// code to populate table
??

}

$("#gl").append(gl);
}

What do I write in buildTable()? Also if my json contains 1000 rows, what's the best way to build table?

Please give an example and explanation. Thanks

http://jsfiddle.net/9u4zR/1/

Barmar

Something like this:

function buildTable(DATA){
    var table = "<table>";
    $.each(DATA.music, function(index, value) {
        table += "<tr><td>" + value.col1 + "</td><td>" + value.col2 + "</td></tr>";
    }
    table += "</table>";
    $("#gl").append(table);    
}

Of course, you need to replace col1 and col2 with the names of your actual properties, and add more columns as needed. You'll also probably want to specify classes or styles. But this shows you the general structure, you can refine it as needed for your application.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Filling nulls with data from other rows

From Dev

Filling nulls with data from other rows

From Dev

How to return rows of data from a table with json?

From Dev

Filling in missing rows in a table

From Dev

Filling SVG element, working on data from JSON

From Dev

How to subset multiple rows from data.table fast on big data

From Dev

How to subset multiple rows from data.table fast on big data

From Dev

Conditionally filling rows of a data frame

From Dev

Extracting some data from big JSON data

From Dev

Error filling an object array from JSON data using DataContractJsonSerializer

From Dev

Deleting many rows from a big table MySql 5.5.46

From Dev

Filling a junction table with mock data

From Dev

AngularJS ng-repeat is creating three empty rows when filling table with JSON array

From Dev

filling up a table empty rows with a border css

From Dev

Filling table from DataTable in MVC

From Dev

Filling table from DataTable in MVC

From Dev

Editable rows is not working in table with JSON data?

From Dev

dynamically inserting rows of json data into existing table

From Dev

Filling missing rows two data frames

From Dev

Using jQuery to build table rows from Ajax response (not with static json data)

From Dev

Filling NSMutableArray from Json Response

From Dev

Filling multidimensional array from JSON

From Dev

Filling a UIPageViewController with data from a server?

From Dev

Update rows with data from the same table

From Dev

Update rows with data from the same table

From Dev

Get data from checked rows of table

From Dev

Scrapy pull data from table rows

From Dev

Move mysql data from rows to a pivot table

From Dev

Delete rows from a data table that exists in another data table

Related Related

HotTag

Archive