Use of chinese-string plugin for ordering

Use of chinese-string plugin for ordering

djmm68djmm68 Posts: 20Questions: 7Answers: 0

I suposse it must be trivial, but now i'm stuck. The question is how can i make use of chinese-string plugin for sorting special characters (with accents, pe.)?

I've seen the following plugin
//cdn.datatables.net/plug-ins/1.10.13/sorting/chinese-string.js

but the trials I've carried out have failed. Where (in the js code) must I apply or call this plugin?

A piece of my code, obtained using DTE Generator, is

```var table = $('#mytable').DataTable( {
    ajax: 'php/table.mytable.php',
    columns: [
        {
            "data": "user"
        },
        {
            "data": "name"
        },
        {
            "data": "group"
        },
        {
            "data": "phone"
        },
        {
            "data": "email"
        }

    ],
    order: [[ 1, 'asc' ]],```

if I try to apply the example to my own case:

$('#mytable').dataTable( { columnDefs: [ { type: 'chinese-string', targets: 0 } ] } );

It thows a "Cannot reinitialise DataTable" error.
Should I put it in the editor initialisation (var editor = new $.fn.dataTable.Editor...)?

This question has an accepted answers - jump to answer

Answers

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

    Add the columns.type option into your existing column objects. For example:

    {
      data: "user",
      type: "chinese-string"
    }
    

    Allan

  • djmm68djmm68 Posts: 20Questions: 7Answers: 0

    Ok, I admit I did not do too much testing before asking :neutral:

    In the code above, before "order: [[ 1, 'asc' ]]" (used to fix order on loading data, prior to show them to end user), it's necessary to set "columnDefs" parameter, so:

    columnDefs: [ {type: "chinese-string", targets: "_all"} ],

    I just discovered the previous option, but I noticed that it affects all the columns (numerics too); moreover your answer is even simpler, thanks!!

This discussion has been closed.