This commit is contained in:
王思川 2024-06-01 11:09:36 +08:00
parent 0ffb7f4c86
commit 06b4bc00a0
1 changed files with 54 additions and 53 deletions

View File

@ -128,69 +128,70 @@ $(document).ready(function() {
});
});
function updateTable() {
var tableBody = $('#form-input-table tbody');
tableBody.empty(); // 清空表体内容
// 更新表格内容,处理分页按钮的点击事件
function updateTable() {
var tableBody = $('#form-input-table tbody');
tableBody.empty(); // 清空表体内容
var upload_excel_preview_config = {{ upload_excel_preview_config|safe }};
var upload_excel_preview_config = {{ upload_excel_preview_config|safe }};
var startIndex = (currentPage - 1) * rowsPerPage;
var endIndex = startIndex + rowsPerPage;
var pageData = tableData.slice(startIndex, endIndex);
var startIndex = (currentPage - 1) * rowsPerPage;
var endIndex = startIndex + rowsPerPage;
var pageData = tableData.slice(startIndex, endIndex);
// 遍历分页数据行
$.each(pageData, function(index, rowData) {
var row = $('<tr>'); // 创建新的行元素
row.append($('<td>').text(startIndex + index + 1)); // 添加序号列
// 遍历分页数据行
$.each(pageData, function(index, rowData) {
var row = $('<tr>'); // 创建新的行元素
row.append($('<td>').text(startIndex + index + 1)); // 添加序号列
var cellIndex = 0; // 初始化列索引
var cellIndex = 0; // 初始化列索引
// 为每个单元格创建对应的输入框或下拉菜单
$.each(upload_excel_preview_config.rows, function(key, cell) {
var cellElement;
var cellValue = rowData[cellIndex] || ''; // 通过列索引获取值
// 为每个单元格创建对应的输入框或下拉菜单
$.each(upload_excel_preview_config.rows, function(key, cell) {
var cellElement;
var cellValue = rowData[cellIndex] || ''; // 通过列索引获取值
if (cell.type === 'text') {
// 创建输入框
cellElement = $('<input>').attr({
style: "width: " + cell.width,
type: 'text',
class: 'form-control',
id: key,
name: key,
value: cellValue,
});
} else if(cell.type === 'select') {
// 创建下拉菜单
cellElement = $('<select>').attr({
style: "width: " + cell.width,
class: 'form-control',
id: key,
name: key,
});
// 添加选项
$.each(cell.options, function(optionIndex, optionValue) {
var optionElement = $('<option>').val(optionValue).text(optionValue);
if(cellValue === optionValue) {
optionElement.attr('selected', 'selected');
}
cellElement.append(optionElement);
});
}
if (cell.type === 'text') {
// 创建输入框
cellElement = $('<input>').attr({
style: "width: " + cell.width,
type: 'text',
class: 'form-control',
id: key,
name: key,
value: cellValue,
});
} else if(cell.type === 'select') {
// 创建下拉菜单
cellElement = $('<select>').attr({
style: "width: " + cell.width,
class: 'form-control',
id: key,
name: key,
});
// 添加选项
$.each(cell.options, function(optionIndex, optionValue) {
var optionElement = $('<option>').val(optionValue).text(optionValue);
if(cellValue === optionValue) {
optionElement.attr('selected', 'selected');
}
cellElement.append(optionElement);
});
}
// 将输入框或下拉菜单添加到单元格中
var td = $('<td>').append(cellElement);
row.append(td);
// 将输入框或下拉菜单添加到单元格中
var td = $('<td>').append(cellElement);
row.append(td);
cellIndex++; // 增加列索引
});
tableBody.append(row); // 将新的行元素添加到表体中
cellIndex++; // 增加列索引
});
// 更新分页信息
$('#pageInfo').text('第 ' + currentPage + ' 页, 共 ' + Math.ceil(tableData.length / rowsPerPage) + ' 页');
}
tableBody.append(row); // 将新的行元素添加到表体中
});
// 更新分页信息
$('#pageInfo').text('第 ' + currentPage + ' 页, 共 ' + Math.ceil(tableData.length / rowsPerPage) + ' 页');
}
$('#prevPage').on('click', function() {
if (currentPage > 1) {