{"action":"closed","issue":{"url":"https://api.github.com/repos/bootstrap-vue/bootstrap-vue/issues/1709","repository_url":"https://api.github.com/repos/bootstrap-vue/bootstrap-vue","labels_url":"https://api.github.com/repos/bootstrap-vue/bootstrap-vue/issues/1709/labels{/name}","comments_url":"https://api.github.com/repos/bootstrap-vue/bootstrap-vue/issues/1709/comments","events_url":"https://api.github.com/repos/bootstrap-vue/bootstrap-vue/issues/1709/events","html_url":"https://github.com/bootstrap-vue/bootstrap-vue/issues/1709","id":309443392,"node_id":"MDU6SXNzdWUzMDk0NDMzOTI=","number":1709,"title":"Default `sort-compare` function in documentation is misleading","user":{"login":"Morgul","id":770655,"node_id":"MDQ6VXNlcjc3MDY1NQ==","avatar_url":"https://avatars2.githubusercontent.com/u/770655?v=4","gravatar_id":"","url":"https://api.github.com/users/Morgul","html_url":"https://github.com/Morgul","followers_url":"https://api.github.com/users/Morgul/followers","following_url":"https://api.github.com/users/Morgul/following{/other_user}","gists_url":"https://api.github.com/users/Morgul/gists{/gist_id}","starred_url":"https://api.github.com/users/Morgul/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Morgul/subscriptions","organizations_url":"https://api.github.com/users/Morgul/orgs","repos_url":"https://api.github.com/users/Morgul/repos","events_url":"https://api.github.com/users/Morgul/events{/privacy}","received_events_url":"https://api.github.com/users/Morgul/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-03-28T16:37:36Z","updated_at":"2018-11-05T10:19:46Z","closed_at":"2018-11-05T10:19:46Z","author_association":"NONE","body":"The default `sort-compare` function from https://bootstrap-vue.js.org/docs/components/table#sort-compare-routine is given as follows:\r\n\r\n```javascript\r\nif (typeof a[key] === 'number' && typeof b[key] === 'number') {\r\n  // If both compared fields are native numbers\r\n  return a[key] < b[key] ? -1 : (a[key] > b[key] ? 1 : 0)\r\n} else {\r\n  // Stringify the field data and use String.localeCompare\r\n  return toString(a[key]).localeCompare(toString(b[key]), undefined, {\r\n    numeric: true\r\n  })\r\n}\r\n```\r\n\r\n_However_, if you try to use that, it will run, but anything other than numbers will sort equal to each other. This is because, `window.toString()` is a function, and therefore valid, except it doesn't do what you would expect at all:\r\n\r\n![image](https://user-images.githubusercontent.com/770655/38042129-1ecc665a-3279-11e8-9d6b-52a06aae9570.png)\r\n\r\nThe key here is that the documentation fails to include the `toString` function used in the code:\r\n\r\n```javascript\r\nfunction toString (v) {\r\n  if (!v) {\r\n    return ''\r\n  }\r\n  if (v instanceof Object) {\r\n    return keys(v)\r\n      .map(k => toString(v[k]))\r\n      .join(' ')\r\n  }\r\n  return String(v)\r\n}\r\n```\r\n\r\nIt took me about an hour to work out that was the problem, when I was building a default case for my sort compare based off the default (but running through the `formatter` functions first, if they existed)."}}
{"actor":{"display_login":"tmorehouse"}}