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

232
Visualizações
Combine el valor JSON en una tabla de fila en dataTable

Tengo un problema con dataTable usando el objeto JSON, aquí está la definición de columnas:

 $(document).ready(function() { $('#tb_kehadiran').DataTable({ processing: true, serverSide: true, scrollX: true, order: [], //init datatable not ordering ajax: "<?php echo site_url('ajax-readabsen')?>", columns: [ {data: 'no', orderable:false}, {data: 'abs_hari'}, {data: 'abs_tgl'}, {data: 'abs_datang', orderable:false}, {data: 'abs_pulang', orderable:false}, {data: 'abs_status'}, ] }); });

Quiero combinar dos valores de Objeto en una fila, intenté hacer esto:

 {data: 'abs_hari'} + " " +{data: 'abs_tgl'},

Pero no funciona,

¿Puedes ayudarme a resolver esto?

Gracias por cualquier idea.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Tienes un par de opciones para hacerlo.

1. Opción ajax.dataSrc :

Con esta opción, puede manipular los datos que recibe de ajax ANTES de que se utilicen como fuente para su tabla. Luego devuelve NUEVOS datos que serán la nueva fuente:

 $(document).ready(function() { $('#tb_kehadiran').DataTable({ processing: true, serverSide: true, scrollX: true, order: [], //init datatable not ordering ajax: { url: "<?php echo site_url('ajax-readabsen')?>", dataSrc: function(originalJson) { // run logic to manipulate your originalJson. // Combine, split, do whatever you want. // For example, create a new field // combining the data of 'abs_hari' and 'abs_tgl' // and call it 'abs_my_new_data_hari_tgl'. return newJson; // <- this will be the new data source for your table }, }, columns: [ {data: 'no', orderable:false}, // {data: 'abs_hari'}, // {data: 'abs_tgl'}, {data: 'abs_my_new_hari_tgl_data_src'}, {data: 'abs_datang', orderable:false}, {data: 'abs_pulang', orderable:false}, {data: 'abs_status'}, ] }); });

2. opción columns.render :

Use una función personalizada para representar datos dentro de una columna específica de su tabla:

 $(document).ready(function() { $('#tb_kehadiran').DataTable({ processing: true, serverSide: true, scrollX: true, order: [], //init datatable not ordering ajax: "<?php echo site_url('ajax-readabsen')?>", columns: [ {data: 'no', orderable:false}, // {data: 'abs_hari'}, // {data: 'abs_tgl'}, { data: null, // can be null but also one of your data field ie 'abs_hari' render: myCustomRenderFunction }, {data: 'abs_datang', orderable:false}, {data: 'abs_pulang', orderable:false}, {data: 'abs_status'}, ] }); }); // define a render function function myCustomRenderFunction(data, type, row, meta) { if(type === 'display') { return row['abs_hari'] + " " + row['abs_tgl'] // this is used to display in the table } else { return data; // original data of the cell from your source. this is used for functionalities other than display (like sorting, odering) } }
over 4 years ago · Santiago Trujillo 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