Ho to avoid sorting but keep the search field, "Show nn entries", etc?
Ho to avoid sorting but keep the search field, "Show nn entries", etc?

Hi there.
I am using a very basic implementation of DataTables in one of my password-protected websites. Thus I cannot show a URL here.
In my PHP script, I include a local copy of dataTables.dataTables.css, dataTables.bootstrap4.min.css, jquery.dataTables.min.js, and dataTables.bootstrap4.min.js.
Then I create the properly sorted table using PHP. Afterwards, I simply call this JavaScript:
// DataTable
echo "<script>\n";
echo "$('#TP_clients_vwd').DataTable();\n";
echo "</script>\n";
I recognized that my table is badly sorted after this, listing Names with German Umlauts behind the regular letters, so everything's fine except that the DataTables script itself resorts my already sorted table data, damaging my German phonebook alphabetical order (which means, that e.g. "ä" is sorted like "ae", "ö" like "oe", "ü" like "ue", "ß" like "ss" etc.).
I then tried and switched off the DataTables sorting, using this change:
// DataTable
echo "<script>\n";
// fade DataTable sorting, because the table is sorted already
echo "new DataTable('#TP_clients_vwd', { order: false });\n";
echo "$('#TP_clients_vwd').DataTable();\n";
echo "</script>\n";
But then the Search field and all additional DataTables UI gimmicks like "Show nn entries", "[Previous | 1 | 2 | Next]" are gone, too.
How can I use DataTables properly but without it having the table data resorted on its own?
Any help or hint is really appreciated.
Best, Ulf
This question has an accepted answers - jump to answer
Answers
You can use
order: []
to have Datatables order the data as supplied by the data source. See the first example in theorder
docs.Use
ordering
to disable the end users ability to click and sort the entire table orcolumns.orderable
to disable sorting per column.Kevin
Another option to allow Datatables to sort the column is to try the diacritic sorting plugin.
Kevin
The diacritic sorting plugin shouldn't actually be needed any more with DataTables 2. Are you able to PM me a login to your page so I can take a look at what is going wrong?
That said, as Kevin says, you can also disable DataTable's sorting if you prefer.
Allan
Thank you all for your comments and recommendations. "order: []" doesn't change the behavior, compared with "order: false". DataTable doesn't sort in both cases, but also removes the navigation elements mentioned in my initial posting.
That suggests to me that you've actually got a Javascript error on the page. If you look at the browser's console, is there anything shown there? Can you link to the page or show us the full JS initialisation for the DataTable?
Allan
Hi Ulf,
I use the international order plug in
https://datatables.net/plug-ins/sorting/intl
I have two languages on my pages, English and German. This is how I handle it. Works fine. I run this code prior to data table initialization.
With the current version of the Plug-In you might have to use it this way:
Roland
I knew there was a plugin that provided locale specific options but I couldn't remember its name! Many thanks @rf1234!
Allan
@Allan: Thank you for pointing me to the Browser console. That did the trick. Now that I tidied up my code this simple version does all that I wanted:
// DataTable
echo "<script>\n";
echo "$('#TP_clients_vwd').DataTable( {order:[]} );\n";
echo "</script>\n";
Thank all of you for this extraordinary forum and your helpful comments. This kind of support has become very rare. I really appreciate it.
Best, Ulf