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

115
Visualizações
How to create a counter column in a jQuery DataTable?

I have a datatable that only displays records that are in the workflow step = "Waiting", which is the first step in the workflow.

I need to create a column that displays data similar to the following:

If record IDs are [95, 87, 65, 34, 12], then this new column would display [5, 4, 3, 2, 1].

If the datatable is sorted by this new column in ascending order, then the values would be => record IDs [12, 34, 65, 87, 95] new column [1, 2, 3, 4, 5].

If record 95 has its workflow step updated to != "Waiting", then the values would be => record IDs [12, 34, 65, 87] new column [1, 2, 3, 4].

I tried the following, but the values/numbers are not sorted as desired:

{
    render: function (data, type, full, meta) {
        return meta.row + 1;
    }
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

What if you tried something like this:

//Create an array for your records. Add zero to avoid index 0
var recordIds = [12, 34, 65, 87, 95];
var recordIdArray = $.merge([0], recordIds)

//sort it by record ID in case it's not in order
recordIds.sort();

//assign index position as New Column value
$.each(recordIdArray, function (index, value) {

    //create table row example
    if (index > 0) {
        var tableRow = "<tr><td>"+index+"</td><td>"+value+"</td></tr>";
        console.log("NewCol: " + index + " || Record ID: " + value);
    }

    //append data to your dataTable here. Example: $("#datatable tbody").append(tableRow);

});
about 4 years ago · Juan Pablo Isaza Relatório
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