Код: Выделить всё
function sum_sales_table() {
var result = [];
// iterate over each row and find all the numbers that are needed to sum up.
$('#table_sales > tbody > tr').each(function() {
if ($(this).attr("id") != "bootstrap-overrides") {
$('td.sumtable', this).each(function(index, val) {
// sum up the numbers and give in to result array.
if (!result[index]) result[index] = 0;
result[index] += parseFloat($(val).text());
});
}
});
// create and design the sum row
$('#table_sales > tbody:last-child').append('');
$('#table_sales > tbody:last-child > tr:last').append('[i][/i]');
$('#table_sales > tbody:last-child > tr:last').append('Total');
// print the sum row numbers
$(result).each(function(i) {
if (i == PROFIT_INDEX) {
$('#table_sales > tbody:last-child > tr:last').append(''+ parseFloat(this) +'')
}
else if (i == PROMOTED_INDEX) {
$('#table_sales > tbody:last-child > tr:last').append(''+ parseFloat(this) +'')
}
else if (i == EBAYTAX_INDEX) {
$('#table_sales > tbody:last-child > tr:last').append(''+ parseFloat(this) +'')
}
else {
$('#table_sales > tbody:last-child > tr:last').append(''+ parseFloat(this) +'')
}
});
// fill out blank columns
$('#table_sales > tbody:last-child > tr:last').append('')
$('#table_sales > tbody:last-child > tr:last').append('')
}
Код: Выделить всё
$(document).ready(function() {
sum_sales_table();
}
Это функция, которая заставляет строку исчезнуть:
Код: Выделить всё
function return_sale() {
tr = $(this).parent("td").parent("tr")
if (tr.attr('id') == "bootstrap-overrides") {
// sale is coming back to life
tr.attr("id", "");
$.ajax({
url: "/cancel_return_sale",
type: "POST",
data: {
sale_id: $(this).data('id'),
},
success: function(data) {
// update total profit
$("#total-profit").html(parseFloat(parseFloat($("#total-profit").text().replace('$', '')) + parseFloat(data.profit)))
tr.toggleClass('warningrow');
// reload sales table and sum row
$("#table_sales").load(location.href + " #table_sales");
// update balance
$("#div_user_balance").load(location.href + " #div_user_balance")
$("#balance_modal_title").load(location.href + " #balance_modal_title")
}
})
.fail(function(data) {
console.log(data);
});
}
}
Я также пробовал вызывать sum_sales_table() при загрузке таблицы, а также сразу после обновления таблицы.>
Подробнее здесь: https://stackoverflow.com/questions/668 ... ding-table
Мобильная версия