Difficulty getting plug-ins diacritics-sort and natural to work

Difficulty getting plug-ins diacritics-sort and natural to work

ma_robergema_roberge Posts: 29Questions: 9Answers: 0

I must confess to still be using version 1.10.21, which works fine for me, and need time before implementing version 2. I have difficulty getting plug-in diacritics-neutralise to work. I have reduced the table in the test case to 14 entries and modified the first column to test sorting; one thus needs to set the table to display more than 10 entries per page. Note the following:

  • Ökonomie should come before Oracle;
  • schön before Schubert;
  • À propos at the top, followed by (in this order) été, Été, Été, étêter, ethnie;
  • Été is used twice, and été once, but the lowercase version is sorted between the two capitalized ones.

The correct order should thus be: À propos, été, Été, Été, étêter, ethnie, étirer, étoffe, Ökonomie, Oracle, Schomberg, Schön, Schubert, sève. Why is it not achieved?

Furthermore, with regard to the natural plug-in, is it correct to use both “nohtml” and “ci” on two separate lines, or should the two commands be merged and how?

{ type: 'natural-nohtml', targets: '_all'},
{ type: 'natural-ci', targets: '_all'}

Are the following lines equivalent, or is one preferable:

{ targets: 0; type: 'diacritics-neutralise'}
{ type: 'diacritics-neutralise'; targets: '_all' }

Answers

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

    The natrual-nohtml type produces the sorting you want: https://live.datatables.net/zefehawa/2/edit .

    The natural sorting for 2.x has been massively simplified and now uses localeCompare. The source is interesting (if you like that sort of thing).

    Furthermore, with regard to the natural plug-in, is it correct to use both “nohtml” and “ci” on two separate lines, or should the two commands be merged and how?

    A column can have only one type, so one would overwrite the other there. The -ci is case-insensitive, which it doesn't sound like what you want. There isn't a natrual-ci-nohtml type - maybe I should add that...

    Allan

  • ma_robergema_roberge Posts: 29Questions: 9Answers: 0

    Thank you for your reply, which shows correct sorting. I see that the only difference is that you have commented out line var table = new DataTable('#example'); in the JavaScript column. The problem is that I have no such line in my code, which I am reproducing below. My knowledge of JavaScript is not advanced enough to really know how to circumvent the problem.

    Of course, the test case uses version 2.0.5, and my code 1.10.21; could it be the culprit? I have tried replacing the version numbers at the top following the cdn.datatables.net bits in the <head> section of the test case, but to no avail; the old versions no longer seem to be on your server.

    In the <head> section (template)

    <script src="DataTables-1.10.21/datatables.min.js"></script>
    <!-- DataTables customized default values-->
    <script>
      $.extend($.fn.dataTable.defaults, {
        "dom": '<"top"l>frt<"bottom"ip><"clear">',
        "order": [],
        "paging": false,
        "language": {
          "search": "Search entire table:"
        }
      });
    </script>
    

    In the <body> section, just before the tables (each of which is identified with table1 table2, etc.)

    <script>
    $(document).ready(function() {
        $("table[id^='table']").DataTable( {
              "columnDefs": [
                { type: 'natural-nohtml', targets: '_all'},
           ]
        });
    } ); 
    $(document).ready(function() {
        $("table[id^='table'] tfoot th").each( function () {
        var title = $( this ).text();
        $(this).html( '<input type="text" placeholder="Search '+title+'" />' );
    } );
    $("table[id^='table']").each( function () {
       var table = $(this).DataTable();
        table.columns().every( function () {
            var that = this;
            $( 'input', this.footer() ).on( 'keyup change', function () {
                that
                    .search( this.value )
                    .draw();
            } );
        } );
      });
    } );
    </script>
    
  • allanallan Posts: 61,822Questions: 1Answers: 10,127 Site admin

    I see that the only difference is that you have commented out line var table = new DataTable('#example');

    I did that because you have the initialisation in the "HTML" tab:

    $(document).ready(function() {
        $('#example').DataTable( {
              "columnDefs": [
                { type: 'natural-nohtml', targets: '_all'},
    //          { type: 'natural-ci', targets: '_all'},
    //          { targets: 0; type: 'diacritics-neutralise'}
    //            { type: 'diacritics-neutralise'; targets: '_all' }
           ]
        });
    } ); 
    

    My change for the original was to comment in the natrual-nohtml type and comment out any others that were enabled.

    { type: 'natural-nohtml', targets: '_all'},

    Like in your code snippet should be all that is needed. If that isn't working for you, could you give me a link to a test case showing that issue (you can PM me the link if you don't want you make your page public).

    Allan

Sign In or Register to comment.