Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 81728

Sort by doc_nr + year. how to

$
0
0

I don't know how to implement a simple way to sort a column that show me number of doc with trailing year like:

COL 1    COL 2     COL 3    DOC. NR
------------------------------------
  x        x          x       2/2020
------------------------------------
  x        x          x       3/2020
------------------------------------
  x        x          x       4/2021
------------------------------------
  x        x          x       1/2022
------------------------------------

In my example i'd like to sort doc. nr col by asc or desc, based on number of doc (grouped by year).

I tried to set data-order with formula: numberdoc + year but it doesn't work cause, for example, 3 + 2020 is equal to 1 + 2022.... so this way is not correct. Any idea?

<td data-order="2020">1/2019</td>

Script:

$(document).ready( function () {
  var table = $('#example').DataTable({
     "aaSorting": [[ 1, "desc" ]],
    "columnDefs": [
            {
                targets: [1],
                data: {
                    _: "1.display",
                    sort: "1.@data-order",
                    type: "1.@data-order"
                }
            }
        ]
  });
} );

My fiddle: http://live.datatables.net/jivekefo/1/edit

Expected: (ASC)

1/2018
2/2018
3/2018
1/2019
2/2019
3/2019
4/2019
1/2020
...

Viewing all articles
Browse latest Browse all 81728

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>