How can I disable the "Auto-detected columns type"?
How can I disable the "Auto-detected columns type"?
Mat786786
Posts: 6Questions: 1Answers: 0
Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:
Answers
You can use
DataTable.type()
and set the function fordetect
to returnfalse
- e.g.There is more discussion about type detection and handling available in the manual.
Allan
Is that what you actually want to do, or do you just want to change a class name or something? You didn't exactly provide a lot of information about what you are trying to do
Allan
Thanks for replying Allan, i'm using jQuery in my project, and i just want to disable by default the auto detect columns type
Fair enough. My post above describes how to do that. You'd need to do it for each of the built in types.
Allan
So if i understand correctly i need to replace this function.
DataTable.type('num', {
className: 'dt-type-numeric',
detect: function ( d, settings )
{
var decimal = settings.oLanguage.sDecimal;
return _isNumber( d, decimal ) ? 'num' : null;
},
order: {
pre: function (d, s) {
var dp = s.oLanguage.sDecimal;
return __numericReplace( d, dp );
}
}
});
to this in datatables.js file?
DataTable.type('num', 'detect', () => false);
No, run the function I gave before you initialise DataTables. Don't modify the DataTables core file.
You'll need to run it for the other built in types as well, like I said.
Allan
It's not working for me, here is my code.
I'm not sure why it is outside the
script
?Sorry my mistake while copying my code in forum.
I have like this in my file:
<script type="text/javascript" language="javascript"›
$(document). ready(function){
DataTable.type('num', 'detect', () => false);
$(' table.datatable'). DataTable({
language:
"url": 'vendor/datatables/localisation/es_es.json'},
responsivé: true, fixedHeader: true, autoWidth: false, pagingType: 'simple', info: true, lengthMenu: [
[15, 50, 100, 300, 500, -1],
[15, 50, 100, 300, 500, "Todos"]
],
fixedHeader:
},
columnDefs: [
headerOffset: $('.navbar').outerHeight(),
targets: 'no-search', searchable: false,
targets: 'no-sort', orderable: false,
targets:
'sort_asc'
orderSequence: ['asc'],
targets:
'sort_desc'
orderSequence: ['desc'],
3);
3);
</script>
I built a test case and it doesn't seem to make the change:
https://live.datatables.net/sofuweve/1/edit
Kevin
That only removes the
num
type. The other types would need to be removed as well:https://live.datatables.net/sofuweve/2/edit
I still have no idea why one want to do that though.
Allan
I the test case
DataTable.type('num', 'detect', () => false);
doesn't seem to remove thenum
type as thedt-type-numeric
is still applied:Possibly I'm missing something
Kevin
Nevermind, looking at it in more detail I see that the Age column can match any of these:
https://live.datatables.net/sofuweve/4/edit
Once these are removed its no longer type detected.
Kevin
Yup, I reused the class name for a few of them
Hey allan,
This worked for me:
But now the problem is that the sorting is not working correctly with numeric columns
No, of course it isn't. Type detection has been disabled and DataTables won't detect numeric columns. It thinks everything is a string.
This is why I asked, back at the start, what it is that you are actually trying to do!
Could you clarify that please? Do you just want the numbers left aligned instead of default right aligned?
For that you could do:
https://live.datatables.net/yofivifi/1/edit
Allan