Difference between revisions of "Dev/Results"
(lol I forgot a return statement) |
(Moved a lot of code around to plug the parsed award data into the table) |
||
Line 17: | Line 17: | ||
<script> | <script> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
Line 75: | Line 59: | ||
− | |||
jQuery(document).ready(function() { | jQuery(document).ready(function() { | ||
− | // var t = jQuery('#table_team').DataTable( { | + | //Request the awards data |
− | + | var resultsRequest = jQuery.ajax({ | |
− | + | url: 'https://igem.org/awards/json_dump.cgi', | |
− | + | type: 'GET', | |
− | + | timeout: 30000, | |
− | + | dataType: "json", | |
− | + | error: function(jqxhr, textStatus, errorThrown) { | |
− | + | alert("AJAX error; look at var resultsRequest"); | |
− | + | }, | |
− | + | success: function(data, textStatus, jqxhr) { | |
− | + | console.log("successfully got team award data, now parsing"); | |
− | + | arrayOfTeamAwards = parseTeamsToAwards(data); | |
− | + | ||
− | + | //Initialize dataTable and set up event bindings. | |
− | + | var t = jQuery('#table_team').DataTable( { | |
− | + | 'lengthMenu': [[10, 25, 50, 100, -1],[10, 25, 50, 100, 'All']], | |
− | + | 'pageLength': -1, | |
− | + | 'deferRender': true, //improves performance | |
− | + | 'data': arrayOfTeamAwards | |
− | + | 'columns': [ | |
− | + | { //Child-table control element | |
− | + | 'className': 'details-control', | |
− | + | 'orderable': false, | |
− | + | 'data': null, | |
− | + | 'defaultContent': '' | |
− | + | }, | |
− | + | {'data': 'team_name'}, | |
− | + | {'data': 'medal',} | |
− | + | {'data': 'award', 'defaultContent': ' '}, | |
− | + | ], | |
− | + | 'order': [[1, 'asc']] //I think this sorts by team-name by default | |
− | + | } ); | |
− | + | ||
− | + | // Add event listener for opening and closing details | |
− | + | $('#table_team tbody').on('click', 'td.details-control', function () { | |
− | + | var tr = $(this).closest('tr'); | |
− | + | var row = t.row( tr ); | |
− | + | ||
− | + | if ( row.child.isShown() ) { | |
+ | // This row is already open - close it | ||
+ | row.child.hide(); | ||
+ | tr.removeClass('shown'); | ||
+ | } | ||
+ | else { | ||
+ | // Open this row | ||
+ | row.child( childRowFormat(row.data()) ).show(); | ||
+ | tr.addClass('shown'); | ||
+ | } | ||
+ | } ); | ||
− | + | jQuery('#table_team').addClass('hover'); //What's this? | |
+ | |||
+ | } | ||
+ | }); | ||
+ | |||
+ | |||
}); | }); | ||
Line 140: | Line 138: | ||
<TH></TH> | <TH></TH> | ||
<TH>Team</TH> | <TH>Team</TH> | ||
− | |||
<TH>Medal</TH> | <TH>Medal</TH> | ||
+ | <TH>Award</TH> | ||
</TR> | </TR> | ||
</THEAD> | </THEAD> |
Revision as of 18:47, 23 September 2015