How can I disable the "Auto-detected columns type"?

How can I disable the "Auto-detected columns type"?

Mat786786Mat786786 Posts: 6Questions: 1Answers: 0

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:

Answers

  • allanallan Posts: 61,822Questions: 1Answers: 10,127 Site admin

    You can use DataTable.type() and set the function for detect to return false - e.g.

    DataTable.type('num', 'detect', () => false);
    

    There is more discussion about type detection and handling available in the manual.

    Allan

  • allanallan Posts: 61,822Questions: 1Answers: 10,127 Site admin

    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

  • Mat786786Mat786786 Posts: 6Questions: 1Answers: 0

    Thanks for replying Allan, i'm using jQuery in my project, and i just want to disable by default the auto detect columns type

  • allanallan Posts: 61,822Questions: 1Answers: 10,127 Site admin

    Fair enough. My post above describes how to do that. You'd need to do it for each of the built in types.

    Allan

  • Mat786786Mat786786 Posts: 6Questions: 1Answers: 0

    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);

  • allanallan Posts: 61,822Questions: 1Answers: 10,127 Site admin

    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

  • Mat786786Mat786786 Posts: 6Questions: 1Answers: 0
    edited February 28

    It's not working for me, here is my code.

    DataTable.type('num', 'detect', () => false);
    <script type="text/javascript" language="javascript"›
    $(document). ready(function){
    $(' 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>
    
  • allanallan Posts: 61,822Questions: 1Answers: 10,127 Site admin

    I'm not sure why it is outside the script?

  • Mat786786Mat786786 Posts: 6Questions: 1Answers: 0

    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>

  • kthorngrenkthorngren Posts: 20,369Questions: 26Answers: 4,777
    edited February 28

    I built a test case and it doesn't seem to make the change:
    https://live.datatables.net/sofuweve/1/edit

    DataTable.type('num', 'detect', () => false);
    
    console.log(DataTable.type('num'))
    
    var table = new DataTable('#example');
    

    Kevin

  • allanallan Posts: 61,822Questions: 1Answers: 10,127 Site admin

    That only removes the num type. The other types would need to be removed as well:

    DataTable.types().forEach(type => {
      DataTable.type(type, 'detect', () => false);
    });
    

    https://live.datatables.net/sofuweve/2/edit

    I still have no idea why one want to do that though.

    Allan

  • kthorngrenkthorngren Posts: 20,369Questions: 26Answers: 4,777

    I the test case DataTable.type('num', 'detect', () => false); doesn't seem to remove the num type as the dt-type-numeric is still applied:

    <tr>
                <td class="sorting_1">Angelica Ramos</td>
                <td>System Architect</td>
                <td>London</td>
                <td class="dt-type-numeric">36</td>
                <td class="dt-type-date">2009/10/09</td>
                <td class="dt-type-numeric">$2,875</td>
              </tr>
    

    Possibly I'm missing something :smile:

    Kevin

  • kthorngrenkthorngren Posts: 20,369Questions: 26Answers: 4,777

    Nevermind, looking at it in more detail I see that the Age column can match any of these:

    DataTable.type('num', 'detect', () => false);
    DataTable.type('num-fmt', 'detect', () => false);
    DataTable.type('html-num', 'detect', () => false);
    DataTable.type('html-num-fmt', 'detect', () => false);
    

    https://live.datatables.net/sofuweve/4/edit

    Once these are removed its no longer type detected.

    Kevin

  • allanallan Posts: 61,822Questions: 1Answers: 10,127 Site admin

    Yup, I reused the class name for a few of them :)

  • Mat786786Mat786786 Posts: 6Questions: 1Answers: 0

    Hey allan,

    This worked for me:

    DataTable.types().forEach(type => {
         DataTable.type(type, 'detect', () => false);
    });
    

    But now the problem is that the sorting is not working correctly with numeric columns

  • allanallan Posts: 61,822Questions: 1Answers: 10,127 Site admin

    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:

    DataTable.type('num', 'className', ' ');
    

    https://live.datatables.net/yofivifi/1/edit

    Allan

Sign In or Register to comment.