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

181
Visualizações
Bootstrap table custom sort for one column only

I have a bootstrap table with the following code:

             <table data-toggle=\"table\" data-url=\"admdata/data2.json\"  data-show-refresh=\"true\" data-show-toggle=\"true\" data-show-columns=\"true\" data-search=\"true\"  data-pagination=\"true\" data-sort-name=\"id\" data-sort-order=\"desc\" data-custom-sort=\"customSort\">

            <thead>
            <tr>
                <th data-field=\"id\" data-sortable=\"true\">ID</th>
                <th data-field=\"name\" data-sortable=\"true\">Имя</th>
                <th data-field=\"fname\" data-sortable=\"true\">Фамилия</th>
                <th data-field=\"phone\" data-sortable=\"true\">Телефон</th>
                <th data-field=\"email\" data-sortable=\"true\">Почта</th>
                <th data-field=\"position\" data-sortable=\"true\">Позиция</th>
                <th data-field=\"role\" data-sortable=\"true\">Роль</th>
                
                                                                                
            </tr>
            </thead>
            </table>

<script>
                function customSort(sortName, sortOrder, data) {
                    var order = sortOrder === 'desc' ? -1 : 1
                    data.sort(function (a, b) {
                        var aa = +((a[sortName] + '').replace(/[^\d]/g, ''))
                        var bb = +((b[sortName] + '').replace(/[^\d]/g, ''))
                        if (aa < bb) {
                            return order * -1
                        }
                        if (aa > bb) {
                            return order
                        }
                        return 0
                    })
                }
            </script>

This is a custom solution from the Bootstrap developers. I have one problem, if I include

data-custom-sort="customSort"

in the table tag I get correct sort on numeric ID values but all other columns sorting stops working. I tried putting the data-custom-sort inside th tag but it didn't work. I want ID column to be sorted by custom sort and other columns as usual, any ideas on how to do that?

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