В моем основном проекте ASP.NET я использовал DataTables jQuery Здесь все идеально, за исключением выравнивания заголовка таблицы и корпуса таблицы. И это произошло после того, как я добавлю полосу прокрутки до того, как он был выровнен с TBody, но я хочу прокрутить. Даже я сделал верным Autowidth, но это не сработало, что мне делать?
< /code>
js код: < /p>
function loadDynamicTable(axis, value, data) {
$.ajax({
url: '@Url.Action("GetDynamicTableData", "Admin")',
data: { 'axis': axis, 'value': value, 'data': data },
type: 'GET',
success: function (response) {
if (response.success) {
if ($.fn.DataTable.isDataTable('#dynamicTable')) {
dataTable.destroy();
}
$("#tableHeader").empty();
$("#tableBody").empty();
response.headers.forEach(function (header) {
$('#tableHeader').append('' + header + '');
});
let grandTotalRow = null;
let tableBodyHtml = "";
response.data.forEach(function (row) {
var rowHtml = '';
row.forEach(function (cell, index) {
if (index === 0) {
cell = cell === "Period Total" ? "Grand Total" : cell;
rowHtml += '' + cell + '';
} else {
rowHtml += '' + Number(cell).toFixed(2) + '';
}
});
rowHtml += '';
if (row[0] === "Grand Total") {
grandTotalRow = rowHtml;
} else {
tableBodyHtml += rowHtml;
}
});
$("#tableBody").html(tableBodyHtml);
if (grandTotalRow) {
$("#tableBody").append(grandTotalRow);
}
dataTable = $('#dynamicTable').DataTable({
destroy: true,
responsive: false,
scrollX: true,
paging: false,
searching: false,
ordering: true,
autoWidth: false,
info: false,
order: [],
drawCallback: function () {
var api = this.api();
var rows = api.rows().nodes();
$(rows).each(function () {
if ($(this).find("td:first").text().trim() === "Grand Total") {
$(this).appendTo("#tableBody");
$(this).addClass("grand-total-row");
}
});
}
});
} else {
alert(response.message);
}
},
error: function () {
alert('Error fetching data.');
}
});
< /code>
} < /p>
css: < /p>
#tableBody tr:last-child td {
font-weight: bold;
background-color: #d9edf7;
}
#dynamicTable td:nth-child(2),
#dynamicTable th:nth-child(2) {
background-color: #d9edf7;
}
.text-right {
text-align: right;
}
.grand-total-row td:first-child {
background-color: transparent !important;
/*font-weight: normal !important;*/
}
.grand-total-row td:nth-child(2) {
background-color: #1a75ff !important;
color: white;
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... ot-aligned
В моих данных jQuery Thead и Tboody не выровнены ⇐ Jquery
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
REACT ERROR
не может быть дочерним элементом . См. (неизвестно) > глава > th
Anonymous » » в форуме Jquery- 0 Ответы
- 32 Просмотры
- Последнее сообщение Anonymous
-