Мне нужно показать / скрыть столбцы в моей таблице начальной загрузки. Если условие истинно, я хочу показать некоторые столбцы и скрыть некоторые другие.
Я пробовал разные методы, но безуспешно
Я использую thymeleaf
для своих просмотров.
Это мой код html-страницы:
МОЙ СТОЛ :
<table data-toggle="table"
th:data-url="@{/certificato/list/{idCommessa}(idCommessa=${commessa.id})}"
data-pagination="true"
data-search="true"
data-classes="table table-hover"
data-striped="true" id="tableCertificato"
data-side-pagination="client">
<thead>
<tr>
<th data-sortable="true" data-field="numeroCertificato" th:text="#{numeroCertificato}"></th>
<th data-sortable="true" data-field="dataCertificato" th:text="#{dataCertificato}" data-formatter="dateFormatter"></th>
<th data-field="nFabbrica" th:text="#{nFabbrica}" ></th>
<th data-field="modulo" th:text="#{modulo}" ></th>
<th data-field="categoriaRischio" th:text="#{categoriaRischio}"></th>
</thead>
Мой JS:
$(function(){
var tipoCertVar = [[${commessa.tipoAttivita}]];
if(tipoCertVar == 'TPED'){
$('#tableCertificato').bootstrapTable('hideColumn', 'nFabbrica');
$('#tableCertificato').bootstrapTable('hideColumn', 'modulo');
$('#tableCertificato').bootstrapTable('hideColumn', 'categoriaRischio');
}else{
$('#tableCertificato').bootstrapTable('showColumn', 'nFabbrica');
$('#tableCertificato').bootstrapTable('showColumn', 'modulo');
$('#tableCertificato').bootstrapTable('showColumn', 'categoriaRischio');
});
Условие истинно, я отладил его с помощью предупреждающего сообщения.
Но столбец скрытия / показа не запускается. Столбцы всегда отображаются.
Я пытаюсь изменить свой код безуспешно так:
<th th:if="${commessa.tipoAttivita != 'TPED' }" data-field="nFabbrica" th:text="#{nFabbrica}"></th>
и с использованием условного data-visible
.
Те же результаты.
Кто-нибудь может мне помочь?