score:15
something like this?
$(function() {
var headers = $("span",$("#tblversions")).map(function() {
return this.innerhtml;
}).get();
var rows = $("tbody tr",$("#tblversions")).map(function() {
return [$("td:eq(0) input:checkbox:checked",this).map(function() {
return this.innerhtml;
}).get()];
}).get();
alert(rows);
});
score:0
i would think it would make more sense to get a json array back from the ajax call and generate your table/chart from that. with jquery templates this isn't hard at all.
score:0
use this line of code:
var arrays = [];
$('table').eq(0).find('tr').each((r,row) => arrays.push($(row).find('td,th').map((c,cell) => $(cell).text()).toarray()))
score:1
something along the lines of:
var tharray = new array();
var contentarray = new array();
$('th').each(function(index) {
tharray[index] = $(this).html();
})
$('tr').each(function(indexparent) {
contentarray['row'+indexparent] = new array();
$(this).children().each(function(indexchild) {
contentarray['row'+indexparent]['col'+indexchild] = $(this).html();
});
});
this gives you two arrays, tharray
which is an array of your headings and contentarray
which is a 2d array containing rows and columns: contentarray['row1']['col0']
returns " value 1,1"
actually, contentarray contains the th
's as well... referenced 'row0'
score:1
does it make more sense to throw a json object back from the ajax query and then render a table and a chart from there?
yes, absolutely. return json in response to your ajax request, then you can render the table using something like jquery templates and use the same underlying data to generate your chart as well.
score:1
here's a modification of jerome wagner's answer that uses recursive maps instead of a map inside an 'each':
http://jsbin.com/oveva3/383/edit
var headers = $("th",$("#meme")).map(function() {
return this.innerhtml;
}).get();
var rows = $("tbody tr",$("#meme")).map(function() {
return [$("td",this).map(function() {
return this.innerhtml;
}).get()];
}).get();
score:1
i'm tinkering with the same thing over here, but i prefer iterating through all tables and writing the header and body arrays into properties of each table, so here's my modification to the original answer:
$(function() {
$("table").each(function(){
var $table = $(this),
$headercells = $("thead th", $(this)),
$rows = $("tbody tr", $(this));
var headers = [],
rows = [];
$headercells.each(function(k,v) {
headers[headers.length] = $(this).text();
$table.prop("headary", headers);
});
$rows.each(function(row,v) {
$(this).find("td").each(function(cell,v) {
if (typeof rows[cell] === 'undefined') rows[cell] = [];
rows[cell][row] = $(this).text();
$table.prop("bodary", rows);
});
});
console.log($(this).prop('headary'));
console.log($(this).prop('bodary'));
});
});
score:3
yet another way of doing it
var headers = jquery('th').map(function(i,e) { return e.innerhtml;}).get();
var datas = []
jquery.each(jquery('tr:gt(0)'), function(i,e ) {
datas.push(jquery('td', e).map(function(i,e) {
return e.innerhtml;
}).get()
);
});
score:17
demo updated http://jsfiddle.net/ish1301/cnsnk/
var header = array();
$("table tr th").each(function(i, v){
header[i] = $(this).text();
})
alert(header);
var data = array();
$("table tr").each(function(i, v){
data[i] = array();
$(this).children('td').each(function(ii, vv){
data[i][ii] = $(this).text();
});
})
alert(data);
Source: stackoverflow.com
Related Query
- HTML table data into arrays via jQuery
- Highcharts display label for pie chart using html table as data source
- HTML table as data source for highstock charts using highcharts
- Stacked Bar type of jquery Highcharts with data from HTML Table
- Use HTML class as Highcharts table data source
- Link table data with chart data Jquery
- Generate chart from html table : JQuery
- Convert JQuery Data into HighChart Format
- Highcharts loading data from a HTML table with a title
- Render Highcharts data table to separate container as chart via drawing API?
- How to populate multi table data in jquery High-chart
- Highcharts Output Data to HTML Table
- using dynamic data from highcharts in a html table
- Highcharts with data populated by php generated html table - only one will load
- Fomatting labels on Y-axis in Highcharts with Data from HTML table
- Jquery & Ajax for data retrieval used for highcharts implementation + HTML
- Highlight relative row in html table when clicking on Highchart data
- javascript Highcharts JSON data to HTML table
- Highchart (pie chart) with data from HTML table not displaying legend
- Angular 5 - Highcharts cannot load data from a HTML table
- HighCharts data defined in a HTML Table using PHP MySQL
- Parsing Data From HTML Table
- Highchart Data from HTML table with <input> values
- Highchart Data from HTML table with line series
- Highcharts combining a column and spline chart from an html data table
- Insert data into jquery highcharts fail
- Insert data into jquery highcharts fail
- Unable to get dynamic data into Jquery pie chart
- Importing data from HTML table to highcharts
- High Chart inserting data from arrays into line graph
More Query from same tag
- Can we add fixed buttons on top of bars in highcharts bar chart
- Plot 400K graphs of 2 points from CSV with Highcharts
- how to use function (chart) in react?
- Using ModalEditor from highcharts-editor in Angular5
- Is it possible to include maplines in highcharter maps?
- Highcharts 3.0 'invisible' columns
- Getting started with Highmaps tooltips
- HighCharts donut chart drilldown
- knockoutjs highcharts parse arrays of data to chart
- Make single bar in highcharts the width of the container
- Highchart value series mapping
- Graphing Data with HighchartsPHP (PHP Wrapper)
- Impossible to have plotband through current date in Highcharts
- HighCharts inside of a javascript function
- Pass JSON-encoded PHP Variable to HighCharts
- R Highcharts heatmap with motion, but motion bar is overlapping with x axis
- HighCharts and Map Bubble are not compatible
- Highcharts problem with decimals if there are many data points
- Highcharts column only show one category
- Implement chartit in Django 1.6 with Python 2.7 - TypeError: 'NoneType' has no attribute __getitem__
- How to web scraping Highcharts values?
- Highstock: Property 'firePointEvent' of object #<Object> is not a function
- Hyperlink bar chart in Highcharter
- Remove DataPoint from x-axis redraw Issues
- Highcharts: Disconnect line when there's no data for position
- Broken y-axis in multiple y-axis settings for Highchart
- Highchart: how to update a dynamic chart by clicking on a button?
- Dot Net Highcharts Series Color
- Highcharts stacked drilldown with n-levels
- Rails 3.1 SQL sum only negative numbers