angular - 在 ngx-datatable angular 4 中使用 *ngIf 隐藏/显示列时,不维护表列的拖放顺序
问题描述
我们试图实现的是,我们希望在刷新页面时保持列的拖放顺序。拖放后,我们将当前列顺序存储在 localStorage 中。下次页面刷新时,我们将获取该列顺序并将其传递给 ngx-datatable。- 这工作正常
我们还使用 *ngIf 来显示/隐藏表格中的列。- 这会导致问题(也许,我不确定)。
以下是我们面临问题的场景:
- 拖放列
- 显示/隐藏列
在第 2 步之后,我们在第 1 步得到的顺序在表格中没有维护,下面是 gif。
<ngx-datatable class="" [columnMode]="'force'" [headerHeight]="70" [footerHeight]="50" [rowHeight]="30" [scrollbarV]="true (activate)="onActivate($event)" (select)="onSelect($event,row)" [scrollbarH]="true" [selectionType]="'single'" [rows]="rows">
<span *ngFor=" let col of dynamicCol;let i = index">
<ngx-datatable-column *ngIf="check_show_hide(i,col) " name="{{col}}" prop="{{col}}" [headerClass]="getIsShowColName" class="draggable">
<ng-template *ngIf="customFilterData[i]" let-sort="sortFn" let-column="column" height="200" ngx-datatable-header-template>
<label class="draggable" draggable="true" (click)="sort()" style="height:10px;cursor:pointer">{{customFilterData[i].name}}</label>
<br>
<input type='text' style='width:100%;height:30px;' placeholder='Filter..' (keyup)='updateFilterNew(customFilterData[i])'
[(ngModel)]="customFilterData[i].value" [hidden]="customFilterData[i].name === 'Serial_No'"/>
</ng-template>
</ngx-datatable-column>
</span> </ngx-datatable>
在上面的代码中,dynamicCol 包含以下格式的列:
dynamicCol = ['FirstName', 'MiddleInitial', ...]
我们headerClass='getIsShowColName'
用于获取列的当前顺序并将其存储在localStorage
.
注意: *ngIf="customFilterData[i]"
用于避免控制台中的错误,因为我们正在使用 -customFilterData[i].name
和customFilterData[i].value
我们需要一个解决方案来维护隐藏/显示功能之后的列顺序。提前致谢
解决方案
推荐阅读
- ruby - 如何在 Jekyll 中修复带有捆绑安装错误的 .rbenv 版本?原因:找不到图片
- java - 如何正确实例化 VLCJ mediaPlayer 的 PixelBuffer
- java - 将带有字符串字段的 Java 对象列表排序为数字
- git - 全新的 git 仓库,没有本地 master
- php - 无法获取表单数组值
- delphi - teechart 2020 试用版安装包缺少入口点
- powershell - Powershell:从文本文件中获取数据
- apache-spark - 处理 Apache Spark 中分区的不良文件夹结构的简单方法
- jquery - 在 jQuery 或 Javascript 中查找不同列的 2 个表之间的匹配数据
- html - 如何缩小“react-image-gallery”中图像的大小?