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

317
Visualizações
Format data returned from JSON in DataTable

I am reading a json file from remote url and displaying it in DataTable.

<script>
    $(document).ready(function () {
        $('#example').DataTable(
            {
            ajax: {
                method: 'GET',
                url: 'https://chainformed.s3.us-east-1.amazonaws.com/Data/mostwatched.json',
                dataSrc: ''
            },
            paging: false,
            responsive: true,
            language: {
    url: "//cdn.datatables.net/plug-ins/1.12.1/i18n/tr.json",
  },

            columns: [
                { "data": "id" },
                { "data": "rank" },
                { "data": "name" },
                { "data": "watchlist" },
                { "data": "percentage" },
                { "data": "difference" },
                { "data": "timestamp" }
                
            ]
        });
        $('.dataTables_length').addClass('bs-select');
    });
</script>

I would like to be able to format and manipulate the data returned from that json file. What is the best way to do it?

For example, i would like to change the values from ({ "data": "watchlist" }) field to number format with comma. How can i achieve it?

I tried this but with no luck: https://datatables.net/reference/option/ajax.dataSrc

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Use render element. Read document from Format output data - orthogonal data and example

Another way u can use columnDefs

<script>
$(document).ready(function () {
    $('#example').DataTable(
        {
        ajax: {
            method: 'GET',
            url: 'https://chainformed.s3.us-east-1.amazonaws.com/Data/mostwatched.json',
            dataSrc: ''
        },
        paging: false,
        responsive: true,
        language: {
url: "//cdn.datatables.net/plug-ins/1.12.1/i18n/tr.json",
},
        columns: [
            { "data": "id" },
            { "data": "rank" },
            { "data": "name" },
            { "data": "watchlist" },
            { "data": "percentage" },
            { "data": "difference" },
            { "data": "timestamp" }
        ],
        'columnDefs': [
            {
              "targets": 3,
              "data": "watchlist",
              "render": function ( data, type, row, meta ) {
                  return data.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
              }
            }
        ]
    });
    $('.dataTables_length').addClass('bs-select');
});
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