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