fix(assets): preserve table row selection and checkbox states during map zoom and reload
This commit is contained in:
parent
b9c481d8e1
commit
b077ed1a74
2 changed files with 22 additions and 5 deletions
|
|
@ -519,7 +519,7 @@ function zoomFormatter(value, row) {
|
|||
|
||||
function buildColumns() {
|
||||
return [
|
||||
{ field: 'check', checkbox: true, width: 36, widthUnit: 'px', align: 'center', valign: 'middle' },
|
||||
{ field: 'state', checkbox: true, width: 36, widthUnit: 'px', align: 'center', valign: 'middle' },
|
||||
{ field: 'actions', title: '', formatter: zoomFormatter, width: 44, widthUnit: 'px', align: 'center', valign: 'middle' },
|
||||
{
|
||||
field: 'code', title: gettext('Code'), sortable: true, width: 135, widthUnit: 'px', valign: 'middle',
|
||||
|
|
@ -896,6 +896,8 @@ $(document).ready(function () {
|
|||
}
|
||||
|
||||
$('#unified-table').bootstrapTable({
|
||||
idField: 'id',
|
||||
selectItemName: 'btSelectItem',
|
||||
columns: buildColumns(),
|
||||
rowStyle: function (row) {
|
||||
if (row && (row.is_dead || row.vitality === 'dead' || row.status === 'dead' || row.status === 'archived')) {
|
||||
|
|
@ -914,12 +916,14 @@ $(document).ready(function () {
|
|||
},
|
||||
onCheck: function (row) {
|
||||
row.state = true;
|
||||
row.check = true;
|
||||
selectedIds.add(row.id);
|
||||
updateSelectionStatus();
|
||||
setMapFeatureSelectionState(row, true);
|
||||
},
|
||||
onUncheck: function (row) {
|
||||
row.state = false;
|
||||
row.check = false;
|
||||
selectedIds.delete(row.id);
|
||||
updateSelectionStatus();
|
||||
setMapFeatureSelectionState(row, false);
|
||||
|
|
@ -2848,9 +2852,16 @@ function loadTableData(features) {
|
|||
const length = Number(p.length ?? p.length_m ?? 0);
|
||||
const area = Number(p.area ?? p.area_m2 ?? p.surface_area ?? p.surface ?? 0);
|
||||
const usageType = p.usage_type_display || '';
|
||||
const isSelected = selectedIds.has(f.id) ||
|
||||
selectedIds.has(String(f.id)) ||
|
||||
(p.id != null && (selectedIds.has(p.id) || selectedIds.has(String(p.id))));
|
||||
if (isSelected) {
|
||||
selectedIds.add(f.id);
|
||||
}
|
||||
return {
|
||||
id: f.id,
|
||||
state: selectedIds.has(f.id),
|
||||
state: isSelected,
|
||||
check: isSelected,
|
||||
code: p.code || '',
|
||||
name: name,
|
||||
asset_type: p.asset_type || '',
|
||||
|
|
@ -2884,6 +2895,8 @@ function loadTableData(features) {
|
|||
$('#unified-spinner').hide();
|
||||
$('#unified-table').bootstrapTable('load', rows);
|
||||
|
||||
syncSelectAllCheckbox();
|
||||
|
||||
updateSelectionStatus();
|
||||
const countBadge = document.getElementById('assets-counter-badge');
|
||||
if (countBadge) countBadge.textContent = rows.length;
|
||||
|
|
@ -3307,6 +3320,7 @@ function selectAllTableRows() {
|
|||
allRows.forEach(r => {
|
||||
selectedIds.add(r.id);
|
||||
r.state = true;
|
||||
r.check = true;
|
||||
setMapFeatureSelectionState(r, true);
|
||||
});
|
||||
$('#unified-table tbody tr').addClass('selected');
|
||||
|
|
@ -3324,6 +3338,7 @@ function deselectAllTableRows() {
|
|||
const allRows = getAllTableRows();
|
||||
allRows.forEach(r => {
|
||||
r.state = false;
|
||||
r.check = false;
|
||||
setMapFeatureSelectionState(r, false);
|
||||
});
|
||||
selectedIds.forEach(id => {
|
||||
|
|
|
|||
|
|
@ -1409,6 +1409,8 @@
|
|||
{# Table #}
|
||||
<table id="unified-table"
|
||||
class="table table-hover table-sm"
|
||||
data-id-field="id"
|
||||
data-select-item-name="btSelectItem"
|
||||
data-pagination="true"
|
||||
data-page-size="100"
|
||||
data-maintain-meta-data="true"
|
||||
|
|
@ -1636,7 +1638,7 @@
|
|||
<script src="{% static 'common/base_script.js' %}"></script>
|
||||
<script src="{% static 'common/base_map.js' %}"></script>
|
||||
<script src="{% static 'assets/sign_panels_shared.js' %}?v=20260703c"></script>
|
||||
<script src="{% static 'assets/asset_symbology.js' %}?v=20261012_circle_select_v4"></script>
|
||||
<script src="{% static 'assets/unified_map_layers.js' %}?v=20261012_circle_select_v4"></script>
|
||||
<script src="{% static 'assets/unified_index.js' %}?v=20261012_circle_select_v4"></script>
|
||||
<script src="{% static 'assets/asset_symbology.js' %}?v=20261012_circle_select_v5"></script>
|
||||
<script src="{% static 'assets/unified_map_layers.js' %}?v=20261012_circle_select_v5"></script>
|
||||
<script src="{% static 'assets/unified_index.js' %}?v=20261012_circle_select_v5"></script>
|
||||
{% endblock script %}
|
||||
Loading…
Reference in a new issue