{"action":"created","issue":{"url":"https://api.github.com/repos/wenzhixin/bootstrap-table/issues/686","labels_url":"https://api.github.com/repos/wenzhixin/bootstrap-table/issues/686/labels{/name}","comments_url":"https://api.github.com/repos/wenzhixin/bootstrap-table/issues/686/comments","events_url":"https://api.github.com/repos/wenzhixin/bootstrap-table/issues/686/events","html_url":"https://github.com/wenzhixin/bootstrap-table/issues/686","id":66194135,"number":686,"title":"sorter function called before data is flattened on a refresh.","user":{"login":"ethompsy","id":6011024,"avatar_url":"https://avatars.githubusercontent.com/u/6011024?v=3","gravatar_id":"","url":"https://api.github.com/users/ethompsy","html_url":"https://github.com/ethompsy","followers_url":"https://api.github.com/users/ethompsy/followers","following_url":"https://api.github.com/users/ethompsy/following{/other_user}","gists_url":"https://api.github.com/users/ethompsy/gists{/gist_id}","starred_url":"https://api.github.com/users/ethompsy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ethompsy/subscriptions","organizations_url":"https://api.github.com/users/ethompsy/orgs","repos_url":"https://api.github.com/users/ethompsy/repos","events_url":"https://api.github.com/users/ethompsy/events{/privacy}","received_events_url":"https://api.github.com/users/ethompsy/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":12,"created_at":"2015-04-03T17:26:41Z","updated_at":"2015-04-09T20:25:29Z","closed_at":null,"body":"Using `bootstrap-table/1.7.0`:\r\n\r\nWhen using a custom sort method I am getting this error on data refresh if the table is sorted by the column using the sort function:\r\n\r\n`Uncaught TypeError: Cannot read property 'indexOf' of undefined`\r\n\r\nThere is definitely data to sort but it appears that the sort function is called with none or undefined data, possibly before the AJAJ call returns. This should never happen. I could check for the case where a or b in undefined, but then the returned sort order is nonsense. Sorting these columns is never a problem. \r\n\r\nThe error ONLY occurs if a) The table is sorted by a column with a custom sort function AND b) The 'refresh' button is clicked on the table (not the browser).\r\n\r\nAlong with this issue I have found that some columns (strangely not all) that DO NOT use a custom sorter will sort fine, but on refresh they will not maintain their sort order. Perhaps this is related.\r\n\r\nI would post a jsFiddle, but this use case requires a call to a JSON endpoint. I don't have any that are external to my app. I can post the code I am using. As you can see I am using the flatJSON option:\r\n\r\n```\r\nfunction fileSizeSorter(a, b) {\r\n  if ( a.indexOf('/') > -1 ) {\r\n    a = $.trim(a.split('/')[0]);\r\n  }\r\n  if ( b.indexOf('/') > -1 ) {\r\n    b = $.trim(b.split('/')[0]);\r\n  }\r\n  aUnit = a.slice(-2, -1);\r\n  bUnit = b.slice(-2, -1);\r\n  units = [ \"B\", \"K\", \"M\", \"G\", \"T\" ];\r\n  aPos = jQuery.inArray( aUnit, units );\r\n  bPos = jQuery.inArray( bUnit, units );\r\n  if (aPos == -1) {\r\n    aUnit = a.slice(-1);\r\n    aPos = jQuery.inArray( aUnit, units );\r\n  }\r\n  if (bPos == -1) {\r\n    bUnit = b.slice(-1);\r\n    bPos = jQuery.inArray( bUnit, units );\r\n  }\r\n  if (aPos > bPos) return 1;\r\n  if (aPos < bPos) return -1;\r\n  if (aPos == bPos) {\r\n    aVal = a.slice(0, -2);\r\n    bVal = b.slice(0, -2);\r\n    if (parseFloat(aVal) > parseFloat(bVal)) return 1;\r\n    if (parseFloat(aVal) < parseFloat(bVal)) return -1;\r\n  }\r\n  return 0;\r\n}\r\n\r\n$storageTable = $('#storage-table').bootstrapTable({\r\n    // classes: [ 'table', 'table-striped', 'table-condensed' ],\r\n    idField: 'computer.id',\r\n    method: 'get',\r\n    url: '/storage-list/.json',\r\n    sortName: \"account-name\",\r\n    sortOrder: \"asc\",\r\n    search: true,\r\n    showColumns: true,\r\n    showRefresh: true,\r\n    showExport: true,\r\n    flat: true,\r\n    striped: true,\r\n    height: ($(window).height() * 0.85),\r\n    formatNoMatches: function () {\r\n      return 'No Computers connected for the Brand(s) shown.';\r\n    },\r\n    formatLoadingMessage: function () {\r\n      message = \"<h1>Loading... </h1></br>\";\r\n      message += \"<img src='{% static \"img/spinner-big.gif\" %}'>\";\r\n      return message;\r\n    },\r\n    refresh: function() {\r\n      $storageTable.html('');\r\n      // Set the time\r\n      setTimeNow('#dateNow', timeOptions);\r\n    },\r\n    onClickRow: function (row) {\r\n      // Do nothing\r\n    },\r\n    columns: [{\r\n      title: 'Info',\r\n      formatter: 'infoButton',\r\n    }, { \r\n      field: 'account.name',\r\n      title: 'Account Name',\r\n      sortable: true\r\n    }, {\r\n      field: 'storage_used',\r\n      title: 'Stored Data',\r\n      sortable: true,\r\n      sorter: 'fileSizeSorter',\r\n    }],\r\n  });\r\n```"},"comment":{"url":"https://api.github.com/repos/wenzhixin/bootstrap-table/issues/comments/91347190","html_url":"https://github.com/wenzhixin/bootstrap-table/issues/686#issuecomment-91347190","issue_url":"https://api.github.com/repos/wenzhixin/bootstrap-table/issues/686","id":91347190,"user":{"login":"ethompsy","id":6011024,"avatar_url":"https://avatars.githubusercontent.com/u/6011024?v=3","gravatar_id":"","url":"https://api.github.com/users/ethompsy","html_url":"https://github.com/ethompsy","followers_url":"https://api.github.com/users/ethompsy/followers","following_url":"https://api.github.com/users/ethompsy/following{/other_user}","gists_url":"https://api.github.com/users/ethompsy/gists{/gist_id}","starred_url":"https://api.github.com/users/ethompsy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ethompsy/subscriptions","organizations_url":"https://api.github.com/users/ethompsy/orgs","repos_url":"https://api.github.com/users/ethompsy/repos","events_url":"https://api.github.com/users/ethompsy/events{/privacy}","received_events_url":"https://api.github.com/users/ethompsy/received_events","type":"User","site_admin":false},"created_at":"2015-04-09T20:25:29Z","updated_at":"2015-04-09T20:25:29Z","body":"@djhvscf This still seems not quite working: https://jsfiddle.net/ethompsy/d5jaL37b/2/\r\n\r\nI declare the columns in javascript. This was working with flatJSON. Now it does not."}}