Sorting datatables columns

Sorting datatables columns

Hildeb67Hildeb67 Posts: 71Questions: 19Answers: 1

Sorting datatables columns when clicking on table column with German date format does not work correctly

can someone help me
Thanks Chris

Answers

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin

    Hi Chris,

    I trust you have looked through the examples for date and time handling? What did you try? Are you using Moment.js or Luxon? Perhaps you can show an example of a date format you are displaying?

    Allan

  • Hildeb67Hildeb67 Posts: 71Questions: 19Answers: 1

    Hello Allan,
    Thanks for the tip, but unfortunately without success. Have

    columnDefs: [
            {
                targets: 3,
                render: DataTable.render.date()
            }
        ]
    

    Can I send you my php file?
    Maybe you have an idea

    greetings Chris

  • Hildeb67Hildeb67 Posts: 71Questions: 19Answers: 1

    Here is an excerpt from the code

            var tablebenutzerverwaltung = $('#benver').DataTable( {
            "language": {
            url: "./resources/ger.json"
            },
            dom: "Bfrtip",  
            //Für diese Einstellung muss im css eine Definition gemacht werden siehe DOM-Tabelle
            //dom: '<"top"<"left-col"B><"center-col"l><"right-col"f>>rtip',
            
            ajax:{       
                url: "./controllers/streckentermineba.php",
                type: 'post',            
                data: { terminjahr: aktuellesjahr} // {Feld in php Datei:Datenfeld das gesendet werden soll}                        
                },
            columns: [
                {
                    data: null,
                    defaultContent: '',
                    className: 'select-checkbox',
                    orderable: false
                },          
                { data: "TERMJAHR"},
                { data: "TERMNR"},      
                { data: "TERMDAT", title: "Termin Datum/Zeit", render: function(d) {return d ? moment(d).format("DD.MM.YYYY HH:mm") : ''} },
                { data: "ANZAHLPLAETZE"},
                { data: "ANZAHLPLAETZEFREI" }
            ],
    columnDefs: [
            {
                targets: 3,
                render: DataTable.render.date()
            }
     ], 
            
            order: [ 1, 'asc' ],
            keys: {
                columns: ':not(:first-child):not(:nth-child(6))',// Spalten für Bearbeitung sperren
                keys: [ 9 ],
                editorpw: editorpw,
                editOnFocus: true
            },
             paging: false,  //Alle Datensätze auf einer Seite anzeigen
            select: {
                style:    'os',
                //selector: 'td:first-child'
                selector: 'td'
            },.........
    
    
  • Hildeb67Hildeb67 Posts: 71Questions: 19Answers: 1

    Thanks, I found it myself
    I replaced this line

            { data: "TERMDAT", title: "Termin Datum/Zeit", render: function(d) {return d ? moment(d).format("DD.MM.YYYY HH:mm") : ''} },    
    

    with the following line

                { data: "TERMDAT", title: "Termin Datum/Zeit", render: DataTable.render.datetime('DD.MM.YYYY HH:mm')
    
  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin

    Thank you for the update - glad to hear you found the solution using a formatting string.

    Allan

Sign In or Register to comment.