sigillum_conf sigillum_conf - 5 months ago 26
Javascript Question

Have a column in datatables.js automatically selected

This is I believe an easy question.

I have a datatable being used in my application, it has a column called "Customer Name" I am trying to have the config for the table done in such was a that a Column name will be automatically selected to display the name of our customers in order as soon as the table loads.

I have not been able to find exactly how (but managed to find solutions to other problems while looking at the docs) to give a better graphic description, this is the table:

enter image description here

See how Inventory Code has the blue arrow automatically selected? How can I make it towards Customer Name being automatically selected instead?

Sorry if this is too basic, I have not found it in the docs, probably been looking in the wrong place, if someone could point me to the correct doc info I would appreciate it.

Thank you.

Answer Source

You can use Default ordering (sorting) for that:

$(document).ready(function() {
   $('#example').DataTable( {
       "order": [[ 1, "asc" ]]

Where 1 stands for the 2 columns here called "Customer Name", as order option is based on zero index. By, default datatable are sorted by 1st column in asc order.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download