Live DOM Sortig works not correctly in one column
Live DOM Sortig works not correctly in one column
acampo
Posts: 3Questions: 2Answers: 0
Hi
The last to rows has to be sorted with ignoring the first letters.
f.e S1,S2,S3,10,S12 etc
It is just working on one column (regal), but sorting on the last one has no affect. Nothing happened.
defined with:
** columnDefs: [
{ "targets": [9,10], "orderDataType": "dom-text-numeric", type: 'numeric' }
],**
Code start here:
```
var editor; // use a global for the submit and return data rendering in the examples
$(document).ready(function() {
editor = new $.fn.dataTable.Editor( {
ajax: "../php/json.php",
table: "#table",
fields: [ {
label: "Kunde:",
name: "kunde"
}, {
label: "AuftragsNr:",
name: "auftragsnr"
}, {
label: "Beschreibung:",
name: "beschreibung"
}, {
label: "Besonderheit:",
name: "besonderheit"
}, {
label: "Bemerkung:",
name: "bemerkung"
}, {
label: "Nutzen:",
name: "nutzen"
}, {
label: "Größe:",
name: "groesse"
}, {
label: "WolfNr:",
name: "wolfnr"
}, {
label: "PDF:",
name: "pdf",
type: "upload",
display: function ( pdf ) {
if(pdf !== null){
var extension = pdf.split('.');
extension = extension[extension.length - 1];
if(extension === 'pdf'){
return '<a href="/uploads/'+pdf+'" target="_blank"><img class="preview" src="/uploads/thumbs/'+pdf+'.png"/></a>';
}else{
return '<a href="/uploads/'+pdf+'" target="_blank"><img class="preview" src="/uploads/'+pdf+'"/></a>';
}
}else{
return '--';
}
},
noImageText: 'Keine Datei'
}, {
label: "Schrank:",
name: "schrank"
}, {
label: "Regal:",
name: "regal"
}
]
} );
$("#table").on( 'dblclick', 'tbody td:not(:first-child)', function (e) {
editor.inline( this );
} );
$.fn.dataTable.ext.order['dom-text-numeric'] = function ( settings, col )
{
return this.api().column( col, {order:'index'} ).nodes().map( function ( td, i ) {
return parseInt(td.textContent.replace( /\D+/,''));
} );
};
$("#table").DataTable( {
dom: "Bfrtip",
language: {
url: '/localization/de.json'
},
colReorder: true,
responsive: true,
ajax: "../php/json.php",
"pageLength": 25,
"search": {
"smart": false
},
columnDefs: [
{ "targets": [9,10], "orderDataType": "dom-text-numeric", type: 'numeric' }
],
columns: [
{ data: "kunde" },
{ data: "auftragsnr" },
{ data: "beschreibung" },
{ data: "besonderheit" },
{ data: "bemerkung"},
{ data: "nutzen"},
{ data: "groesse"},
{ data: "wolfnr"},
{ data: 'pdf', render: function ( data ) {
if(data !== null){
var extension = data.split('.');
extension = extension[extension.length - 1];
if(extension === 'pdf'){
return '<a href="/uploads/'+data+'" target="_blank"><img class="preview" src="/uploads/thumbs/'+data+'.png" height="40" /></a>';
}else{
return '<a href="/uploads/'+data+'" target="_blank"><img class="preview" src="/uploads/'+data+' height="40" /></a>';
}
}else{
return '--';
}
} },
{ data: "schrank"},
{ data: "regal"}
],
select: true,
buttons: [
{ extend: "create", editor: editor, text: "Hinzufügen" },
{ extend: "edit", editor: editor, text: "Editieren" },
{
extend: "selectedSingle",
text: 'Kopieren',
action: function ( e, dt, node, config ) {
var table = $('#table').DataTable();
var values = editor.edit(
table.row( { selected: true } ).index(),
false
)
.val();
// Create a new entry (discarding the previous edit) and
// set the values from the read values
editor
.create( {
title: 'Eintrag kopieren',
buttons: 'Neu erstellen'
} )
.set( values );
}
},
{ extend: "remove", editor: editor, text: "Entfernen" }
]
} );
} );
```
This discussion has been closed.
Answers
You might try the natural sorting plugin:
https://datatables.net/plug-ins/sorting/natural
Kevin