Natural sorting as default sorting

Natural sorting as default sorting

buelentxbuelentx Posts: 3Questions: 2Answers: 0

Hello everbody,

I have a page with 4 datatables.
How can I set natural sorting ( " type: 'natural' '') as default sorting for all columns.

Thanks.

Best Regards
Buelentx

Answers

  • rf1234rf1234 Posts: 3,021Questions: 88Answers: 421

    You can set defaults and make them dependent on the page you are on. Since there is a page refresh every time the user changes the page this works. I use this to set different defaults if the user changes the language of the site.

    Something like this

    If (onMySpecialNaturalSortingPage) {
       $.extend( true, $.fn.dataTable.defaults, {
          columnDefs: [
               { type: 'natural', targets: '_all'  }
           ]
        } );
    }
    

    Since I don't use natural sorting myself I cannot guarantee that this works. Maybe give it a try?!

  • allanallan Posts: 63,691Questions: 1Answers: 10,500 Site admin

    I think you might need to use:

    If (onMySpecialNaturalSortingPage) {
       $.extend( true, $.fn.dataTable.defaults, {
          column: {
               type: 'natural'
          }
        } );
    }
    

    I'm not sure that you can use columnDefs in the defaults. I'll need to check into that...

    Allan

This discussion has been closed.