{"action":"created","issue":{"url":"https://api.github.com/repos/DataTables/DataTables/issues/661","labels_url":"https://api.github.com/repos/DataTables/DataTables/issues/661/labels{/name}","comments_url":"https://api.github.com/repos/DataTables/DataTables/issues/661/comments","events_url":"https://api.github.com/repos/DataTables/DataTables/issues/661/events","html_url":"https://github.com/DataTables/DataTables/issues/661","id":105798176,"number":661,"title":"Individual column searching example - sort based on column data type","user":{"login":"mpryvkin","id":7396482,"avatar_url":"https://avatars.githubusercontent.com/u/7396482?v=3","gravatar_id":"","url":"https://api.github.com/users/mpryvkin","html_url":"https://github.com/mpryvkin","followers_url":"https://api.github.com/users/mpryvkin/followers","following_url":"https://api.github.com/users/mpryvkin/following{/other_user}","gists_url":"https://api.github.com/users/mpryvkin/gists{/gist_id}","starred_url":"https://api.github.com/users/mpryvkin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mpryvkin/subscriptions","organizations_url":"https://api.github.com/users/mpryvkin/orgs","repos_url":"https://api.github.com/users/mpryvkin/repos","events_url":"https://api.github.com/users/mpryvkin/events{/privacy}","received_events_url":"https://api.github.com/users/mpryvkin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-09-10T12:41:25Z","updated_at":"2015-09-10T13:46:04Z","closed_at":null,"body":"[Individual column searching](http://datatables.net/examples/api/multi_filter_select.html) example uses [`sort()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) to sort values in the drop-down boxes, however without an argument `sort()` sorts values as strings.\r\n\r\nIn the example, there is a numeric column **Age** which is only being sorted correctly because all numbers are double-digit. Also **Salary** column is obviously not sorted numerically with **$1,200,000** appearing on top of the list.\r\n\r\nSee [this question on StackOverflow](http://stackoverflow.com/questions/32497582/) for possible solutions."},"comment":{"url":"https://api.github.com/repos/DataTables/DataTables/issues/comments/139238477","html_url":"https://github.com/DataTables/DataTables/issues/661#issuecomment-139238477","issue_url":"https://api.github.com/repos/DataTables/DataTables/issues/661","id":139238477,"user":{"login":"mpryvkin","id":7396482,"avatar_url":"https://avatars.githubusercontent.com/u/7396482?v=3","gravatar_id":"","url":"https://api.github.com/users/mpryvkin","html_url":"https://github.com/mpryvkin","followers_url":"https://api.github.com/users/mpryvkin/followers","following_url":"https://api.github.com/users/mpryvkin/following{/other_user}","gists_url":"https://api.github.com/users/mpryvkin/gists{/gist_id}","starred_url":"https://api.github.com/users/mpryvkin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mpryvkin/subscriptions","organizations_url":"https://api.github.com/users/mpryvkin/orgs","repos_url":"https://api.github.com/users/mpryvkin/repos","events_url":"https://api.github.com/users/mpryvkin/events{/privacy}","received_events_url":"https://api.github.com/users/mpryvkin/received_events","type":"User","site_admin":false},"created_at":"2015-09-10T13:46:04Z","updated_at":"2015-09-10T13:46:04Z","body":"In `initComplete` function you can temporarily sort each column in ascending order and then restore the initial order once all drop-down boxes are added, see the code below.\r\n\r\n```\r\ninitComplete: function (settings, json) {\r\n    // Get initial order\r\n    var orderInit = this.api().order();\r\n\r\n    this.api().columns().every( function (index) {\r\n        var column = this;\r\n        var select = $('<select><option value=\"\"></option></select>')\r\n            .appendTo( $(column.footer()).empty() )\r\n            .on( 'change', function () {\r\n                var val = $.fn.dataTable.util.escapeRegex(\r\n                    $(this).val()\r\n                );\r\n\r\n                column\r\n                    .search( val ? '^'+val+'$' : '', true, false )\r\n                    .draw();\r\n            } );\r\n\r\n        // NOTE: Temporarily sort the column data before retrieving it\r\n        // with data() function.\r\n        column.order('asc').draw(false).data().unique().each( function ( d, j ) {\r\n            select.append( '<option value=\"'+d+'\">'+d+'</option>' )\r\n        } );\r\n    } );\r\n\r\n    // Restore initial order\r\n    this.api().order(orderInit).draw(false);\r\n} \r\n```"}}