122
This commit is contained in:
50
index.html
50
index.html
@@ -406,6 +406,7 @@ SELECT * FROM users LIMIT 10;"></textarea>
|
||||
this.primaryKey = null;
|
||||
this.tableStructure = [];
|
||||
this.filters = {};
|
||||
this.filterColumns = [];
|
||||
this.sortColumn = '';
|
||||
this.sortDirection = 'ASC';
|
||||
this.init();
|
||||
@@ -583,10 +584,13 @@ SELECT * FROM users LIMIT 10;"></textarea>
|
||||
return `<th class="text-left p-3 cursor-pointer hover:bg-slate-100 select-none" onclick="app.sortBy('${col}')">${col} ${arrow}</th>`;
|
||||
}).join('') + '<th class="text-left p-3">Действия</th>';
|
||||
|
||||
// Generate filter inputs
|
||||
filterInputs.innerHTML = columns.map(col => {
|
||||
return `<td class="p-2"><input type="text" placeholder="Фильтр ${col}" class="w-full px-2 py-1 text-xs border border-slate-300 rounded focus:outline-none focus:ring-1 focus:ring-blue-500" oninput="app.updateFilter('${col}', this.value)" value="${this.filters[col] || ''}"></td>`;
|
||||
}).join('') + '<td class="p-2"><button onclick="app.clearFilters()" class="text-xs text-slate-500 hover:text-slate-700">Очистить</button></td>';
|
||||
// Render filter inputs once per column set and keep values in sync
|
||||
if (JSON.stringify(this.filterColumns) !== JSON.stringify(columns)) {
|
||||
this.filterColumns = columns;
|
||||
this.renderFilterRow(columns);
|
||||
} else {
|
||||
this.updateFilterInputs(columns);
|
||||
}
|
||||
|
||||
if (records.length === 0) {
|
||||
body.innerHTML = '<tr><td colspan="100%" class="text-center py-8 text-slate-500">Нет данных</td></tr>';
|
||||
@@ -613,6 +617,23 @@ SELECT * FROM users LIMIT 10;"></textarea>
|
||||
}).join('');
|
||||
}
|
||||
|
||||
// Filter row helpers (do not re-render inputs on every data refresh)
|
||||
renderFilterRow(columns) {
|
||||
const filterInputs = document.getElementById('filterInputs');
|
||||
filterInputs.innerHTML = columns.map(col => {
|
||||
return `<td class="p-2"><input type="text" data-col="${col}" placeholder="Фильтр ${col}" class="w-full px-2 py-1 text-xs border border-slate-300 rounded focus:outline-none focus:ring-1 focus:ring-blue-500" oninput="app.updateFilter('${col}', this.value)" value="${this.filters[col] || ''}"></td>`;
|
||||
}).join('') + '<td class="p-2"><button onclick="app.clearFilters()" class="text-xs text-slate-500 hover:text-slate-700">Очистить</button></td>';
|
||||
}
|
||||
|
||||
updateFilterInputs(columns) {
|
||||
columns.forEach(col => {
|
||||
const input = document.querySelector(`#filterInputs input[data-col="${col}"]`);
|
||||
if (input) {
|
||||
input.value = this.filters[col] || '';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
sortBy(column) {
|
||||
if (this.sortColumn === column) {
|
||||
if (this.sortDirection === 'ASC') {
|
||||
@@ -665,7 +686,15 @@ SELECT * FROM users LIMIT 10;"></textarea>
|
||||
title.textContent = isEdit ? 'Редактировать запись' : 'Добавить запись';
|
||||
|
||||
// Generate form fields based on table structure
|
||||
form.innerHTML = this.tableStructure.map(col => {
|
||||
const columnsToRender = this.tableStructure.filter(col => {
|
||||
// For new records, skip UUID/uid columns so they get generated/ignored by the server
|
||||
if (!isEdit && (col.name.toLowerCase() === 'uid' || col.type.toLowerCase() === 'uuid')) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
form.innerHTML = columnsToRender.map(col => {
|
||||
const value = isEdit && this.editingRecord ? '' : '';
|
||||
let inputHtml = '';
|
||||
|
||||
@@ -746,6 +775,17 @@ SELECT * FROM users LIMIT 10;"></textarea>
|
||||
}
|
||||
});
|
||||
|
||||
// Ensure UUID/UID columns are sent (as empty strings) so the server can auto-generate values
|
||||
if (!this.editingRecord) {
|
||||
this.tableStructure.forEach(col => {
|
||||
if (col.name.toLowerCase() === 'uid' || col.type.toLowerCase() === 'uuid') {
|
||||
if (data[col.name] === undefined || data[col.name] === '') {
|
||||
data[col.name] = '';
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
let response;
|
||||
if (this.editingRecord) {
|
||||
|
||||
Reference in New Issue
Block a user