Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

176
Visualizações
Bootstrap-table Toggle Column with colspan=1

When a grouped header (aka nested) has 1 nested level (like "Price" and "Total" in the example) there is a strange behaviour: I would expect a way to hide the whole column, yet when I hide "Total", "Price" remains visible. Is there a way to hide that? You can see it works fine in case the 2nd level header has more than 1 element: I hide "Id" and "Name" and "Key" is automatically hidden.

https://live.bootstrap-table.com/code/antonioaltamura/6940

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/bootstrap-table@1.19.1/dist/bootstrap-table.min.css">
<script src="https://unpkg.com/bootstrap-table@1.19.1/dist/bootstrap-table.min.js"></script>



<table id="table" border=1>
</table>

<button onclick="togglePrice()">
  togglePrice
</button>
<button onclick="toggleKey()">
  toggleKey
</button>
<script>
  var $table = $('#table')
  var priceVisible = true;
  var keyVisible = true;
  $(function() {
    var data = [
      {
        'id': 0,
        'name': 'Item 0',
        'price': '$0'
      },
      {
        'id': 1,
        'name': 'Item 1',
        'price': '$1'
      },
      {
        'id': 2,
        'name': 'Item 2',
        'price': '$2'
      },
      {
        'id': 3,
        'name': 'Item 3',
        'price': '$3'
      },
      {
        'id': 4,
        'name': 'Item 4',
        'price': '$4'
      },
      {
        'id': 5,
        'name': 'Item 5',
        'price': '$5'
      }
    ]
    $table.bootstrapTable({
      data: data,
      columns: [
        [
          {
            title: "Key",
            colspan:2
          },
          {
            title: "Price",
                        field: "h_price"
          },
        ],
        [
            {title: "Id", field:"id"},
          {title: "Name", field:"name"},
          {title: "Total", field:"price"}
        ]
    ]})
  })
  
  function togglePrice() {
    $table.bootstrapTable(priceVisible ? "hideColumn" : "showColumn", "price")
    priceVisible = !priceVisible
  }
  
  function toggleKey() {
    $table.bootstrapTable(keyVisible ? "hideColumn" : "showColumn", "id")
    $table.bootstrapTable(keyVisible ? "hideColumn" : "showColumn", "name")
    keyVisible = !keyVisible
  }
  
</script>

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda