{"action":"opened","issue":{"url":"https://api.github.com/repos/olifolkerd/tabulator/issues/440","repository_url":"https://api.github.com/repos/olifolkerd/tabulator","labels_url":"https://api.github.com/repos/olifolkerd/tabulator/issues/440/labels{/name}","comments_url":"https://api.github.com/repos/olifolkerd/tabulator/issues/440/comments","events_url":"https://api.github.com/repos/olifolkerd/tabulator/issues/440/events","html_url":"https://github.com/olifolkerd/tabulator/issues/440","id":241815584,"number":440,"title":"How to update formatter on data reload?","user":{"login":"Sledge-","id":5295572,"avatar_url":"https://avatars3.githubusercontent.com/u/5295572?v=3","gravatar_id":"","url":"https://api.github.com/users/Sledge-","html_url":"https://github.com/Sledge-","followers_url":"https://api.github.com/users/Sledge-/followers","following_url":"https://api.github.com/users/Sledge-/following{/other_user}","gists_url":"https://api.github.com/users/Sledge-/gists{/gist_id}","starred_url":"https://api.github.com/users/Sledge-/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Sledge-/subscriptions","organizations_url":"https://api.github.com/users/Sledge-/orgs","repos_url":"https://api.github.com/users/Sledge-/repos","events_url":"https://api.github.com/users/Sledge-/events{/privacy}","received_events_url":"https://api.github.com/users/Sledge-/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-07-10T19:10:17Z","updated_at":"2017-07-10T19:10:17Z","closed_at":null,"body":"I have some code to format cells according to whether or not they match a certain string `thisCohort`.  The value of this string changes every time I load new data, and my intent is is to update the formatter every time I load new data.\r\n\r\n```\r\nvar format3 = d3.format(\",.2f\");\r\n\r\nfunction createTable(tabledata, cohort){\r\n  // $(\"#example-table\").tabulator(\"clearData\");\r\n\r\n  // $(\"#migration-table\").empty();\r\n\r\n  var thisCohort = cohort;\r\n  $(\"#migration-table\").tabulator({\r\n    columns:[\r\n        {\r\n            title:\"Source Cohort\",\r\n            field:\"source_level2_cohort\",\r\n            sorter:\"string\",\r\n            width:150,\r\n            formatter: function(cell, formatterParams){\r\n              var value = cell.getValue();\r\n              return value === thisCohort ? \"<span style='font-weight:bold;'>\" + value + \"</span>\" : value;\r\n            }\r\n        },\r\n        {\r\n            title:\"Target Cohort\",\r\n            field:\"target_level2_cohort\",\r\n            sorter:\"string\",\r\n            width:150,\r\n            formatter: function(cell, formatterParams){\r\n              var value = cell.getValue();\r\n              return value === thisCohort ? \"<span style='font-weight:bold;'>\" + value + \"</span>\" : value;\r\n            }\r\n        },\r\n        {\r\n            title:\"Number of Customers\",\r\n            field:\"cid_count\",\r\n            sorter:\"number\",\r\n            width:150\r\n        },\r\n        {\r\n            title:\"Revenue Change($)\",\r\n            field:\"revenue_difference\",\r\n            sorter:\"number\",\r\n            width:150,\r\n            // formatter:\"money\"\r\n            formatter: function(cell, formatterParams){\r\n              var value = cell.getValue(),\r\n                  sign = value >= 0 ? \"\" : \"-\",\r\n                  color = value >= 0 ? \"black\" : \"red\";\r\n                  text = \"<span style='color:\"+color+\";'>\" +sign +\"$\"+format3(Math.abs(value))+ \"</span>\";\r\n                  // text = \"<font color=\"+color+\">\"+sign +\"$\"+format3(Math.abs(value))+\"</font>\";\r\n              return \"<div>\"+text+\"</div>\";\r\n            }\r\n        }\r\n        // {title:\"Migration Type\", field:\"migration_category\", sorter:\"string\", width:150}\r\n        // {title:\"Gender\", field:\"gender\", sorter:\"string\", cellClick:function(e, cell){console.log(\"cell click\")},},\r\n    ]\r\n  });\r\n\r\n  $(\"#migration-table\").tabulator(\"setData\", tabledata);\r\n\r\n  $(\"#migration-table\").tabulator(\"setSort\", \"revenue_difference\", \"desc\");\r\n};\r\n```\r\n\r\nThere is a user interaction which loads new data to the `tabledata` variable and calls the `createTable()` function. \r\n\r\nWhen I do this, the data is correctly updated in the table, but for some reason my formatter function behaves as if it still has the **original** value of the `thisCohort` variable.  So all the wrong cells are bolded.  I can reload new data multiple times and it's always the original value that is bolded.\r\n\r\nAm I implementing my formatters correctly or is there another way to set this up that will apply the new value of `thisCohort` every time I reload the data."}}
{"actor":{"display_login":"Sledge-"}}