Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

118
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda