I have a cats.json JSON file.
[{ "breed" : "Abyssinian", "country" : "Ethiopia", "coffeePreference" : "espresso", "picture" : "https://upload.wikimedia.org/wikipedia/commons/thumb/9/9b/Gustav_chocolate.jpg/100px-Gustav_chocolate.jpg" }, { "breed" : "Aegean", "country" : "Greece", "coffeePreference" : "medium roast, cream and sugar", "picture" : "https://upload.wikimedia.org/wikipedia/commons/thumb/5/51/Aegean_cat.jpg/100px-Aegean_cat.jpg" }]
The above is a brief snippet. I am trying to load this JSON file using getJson and format it in a sortable table. I can display the table on the screen, but I canβt get the job sort of. I know that the sorting function works in a regular HTML table, and I think it has something to do with my general approach, as I am new to the interface. The code is as follows:
<!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="content-type" content="text/html;charset=Windows-1252"> <style type="text/css"> table { border-collapse: collapse; border: none; } th, td { border: 1px solid black; padding: 4px 16px; font-family: Times New Roman; font-size: 24px; text-align: left; } th { background-color: #C8C8C8; cursor: pointer; } </style> </head> <body> <div id="catTable"></div> <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script> <script> var cats, asc1 = 1, asc2 = 1, asc3 = 1; window.onload = function () { cats = document.getElementById("cats"); } function sort_table(tbody, col, asc) { var rows = tbody.rows, rlen = rows.length, arr = new Array(), i, j, cells, clen; </script> </body> </html>
Any help or direction. will be greatly appreciated.
source share