javascript - get all entries by column name: HTML table -
i have html table of following format:-
+------+----------+----------+----------+ | name | subject1 | subject2 | subject3 | +------+----------+----------+----------+ | xxx | pass | fail | pass | | yyy | pass | pass | pass | | zzz | pass | fail | fail | +------+----------+----------+----------+
the table dynamically created json data obtained server. create every name tag containing names of subject since number of subjects not constant. now, want have lists corresponding subjects.. subject1[],2 , on , these lists contain list of pass/fails associated subject... can compute number of pass/fails subjects , draw graphs.
while aware this:can used rows particular column,
$('#mytable tbody td:nth-col(4)')
this wont useful if number of columns fixed. kindly let me know how accomplish using jquery/js. edit: data.json:-(if parsing can done)
{"students": [{"student": john, "status": "pass", "subject": "english"},{"student": joe, "status": "pass", "subject": "english"},{"student": jill, "status": "fail", "subject": "french"}]}
as discussed in comments, easier aggregate data original source (which javascript object in case) rather extracting visual representation (the dom in case).
to group data based on subject
of each student data:
var res = {}; (var in data.students) { var item = data.students[i]; var subject = item.subject; if (!res[subject]) res[subject] = { passedcount: 0, failedcount: 0 }; if (item.status == 'pass') res[subject].passedcount++; else res[subject].failedcount++; }
see fiddle
Comments
Post a Comment