行转列
function setSemeterData(dnList, yearList, semList) {
if (dnList.length == 0) {
return false;
}
var tbContent = "";
var totalAmount = 0;
var temp = {};
for (var i = 0; i < semList.length; i++) {
if (i == 0) {
tbContent += "<tr><td>学期</td>";
$.each(yearList,
function (idx, val) {
tbContent += "<td>" + val + "年</td>";
});
tbContent += "<td>合计</td></tr>";
}
tbContent += "<tr>";
var row = "<td>" + semList[i] + "</td>";;
var rowSum = 0;
for (var j = 0; j < yearList.length; j++) {
var amt = 0;
for (var k = 0; k < dnList.length; k++) {
if (dnList[k].AcademicYrName == yearList[j] &&
dnList[k].SemesterName == semList[i]) {
amt = dnList[k].PaidAmt;
break;
}
}
var tf = temp[j];
if (tf != undefined) {
temp[j] += amt;
} else {
temp[j] = amt;
}
rowSum += amt;
row += "<td>" + amt.toLocaleString() + "</td>";
}
totalAmount += rowSum;
row += "<td>" + rowSum.toLocaleString() + "</td>";
tbContent += row + "</tr>";
if (i == semList.length - 1) {
tbContent += "<tr><td>收款合计</td>";
$.each(yearList,
function (idx, val) {
tbContent += "<td class='subSum'>" + temp[idx].toLocaleString() + "</td>";
});
tbContent += "<td class='totalAmount'>" + totalAmount.toLocaleString() + "</td></tr>";
}
}
$("#semeterList").html(tbContent);
}