Last active
January 25, 2017 10:36
-
-
Save timkinnane/6149785 to your computer and use it in GitHub Desktop.
dataTable takes an array of key/value objects and return table of elements. e.g from parsed JSON. Requires jQuery.
Widefat class is used for Wordpress admin pages, but its not a WP specific function.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).ready(function($) { | |
function dataTable(data) { | |
var response_table = $('<table class="widefat"></table>'); | |
var header = $('<thead><tr></tr></thead>'); | |
for(var k in data[0]) { | |
header.append('<th>'+k+'</th>'); | |
} | |
response_table.append(header); | |
tbody = $('<tbody></tbody>'); | |
$.each(data, function() { | |
var row = $('<tr></tr>'); | |
$.each(this, function(k, v) { | |
row.append('<td>'+v+'</td>'); | |
}); | |
tbody.append(row); | |
}); | |
response_table.append(tbody); | |
return response_table; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment