Last active
December 29, 2015 14:51
-
-
Save sangar82/adea0a4669d034cdca6c to your computer and use it in GitHub Desktop.
Transforme table to graph
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
// Guardamos en un array los valores | |
var values = []; | |
var headers = []; | |
// get our values (get rows) | |
$('.datatables5 tbody tr').each(function(i, v){ | |
values[i] = []; | |
//miramos cuantas columnas tiene para quitar la última de total | |
length = $(this).children('td').length; | |
c = 1; | |
// select either th or td, doesn't matter | |
$(this).children('th,td').each(function(ii, vv){ | |
if (c < length) | |
{ | |
if (c == 1) | |
values[i][ii] = $(this).html().trim(); | |
else | |
values[i][ii] = parseInt($(this).html().trim()); | |
} | |
c++; | |
}); | |
}); | |
// get headers | |
$('.datatables5 thead tr').each(function(i, v){ | |
headers[i] = []; | |
//miramos cuantas columnas tiene para quitar la última de total | |
length = $(this).children('th').length; | |
c = 1; | |
// select either th or td, doesn't matter | |
$(this).children('th').each(function(ii, vv){ | |
if (c < length) | |
{ | |
if (c != 1) | |
headers[i][ii] = $(this).html().trim(); | |
} | |
c++; | |
}); | |
}); | |
// get by column | |
// get by column headers | |
td = $(' .datatables5 tr > td:nth-child(1)'); | |
td.each(function () { | |
headers.push($(this).html().trim().replace( /<.*?>/g, '' )) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment