Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

280
Views
Problema de clasificación de formato de fecha y hora de tablas de datos

Quiero formatear la columna Fecha. (DD.MM.YYYY HH:mm ) También me sale error en el pedido. La clasificación no funciona en este formato.

ingrese la descripción de la imagen aquí

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

1.) ¿Tiene el script de momento vinculado a su HTML?

SI no, asegúrese de agregar lo siguiente en la etiqueta <head> de su html <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js" referrerpolicy="no-referrer"></script>

Si es así. Puedes hacer lo siguiente.

En lugar de representarlo en columnDefs, en realidad puede reformatear la fecha en la inicialización de la columna de esta manera:

 moment.suppressDeprecationWarnings = true; var dataSet = [ { "Something" : "Something1", "Date" : "01/12/2021" } ] $(document).ready(function() { $('#example').DataTable( { data: dataSet, columns: [ { "data": "Something" }, { "data": "Date", render: function(data, type, row) { //render function to format the date values from my AJAX if (type === "sort" || type === "type") { return data; } return moment(data).format("DD.MM.YYYY HH:mm"); } } ] } ); } );
 <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!--stylesheets--> <!-- <link rel="stylesheet" href="site.css"> --> <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.6.0/css/bootstrap.css"/> <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/bs4-4.6.0/jq-3.3.1/dt-1.11.0/af-2.3.7/date-1.1.1/r-2.2.9/rg-1.1.3/datatables.css"/> <!--scripts--> <!-- <script src="main.js"></script> --> <script type="text/javascript" src="https://cdn.datatables.net/v/bs4-4.6.0/jq-3.3.1/dt-1.11.0/af-2.3.7/date-1.1.1/r-2.2.9/rg-1.1.3/datatables.js"></script> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.6.0/js/bootstrap.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js" referrerpolicy="no-referrer"></script> </head> <body> <div class="container"> <table id="example" class="table table-striped table-bordered" style="width:100%"> <thead class="thead-light"> <tr> <th>Something</th> <th>Date</th> </tr> </thead> </table> </div> </body> </html>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!