I'm using numerous Google visualization Tables to display a variety of data in a single-paged, multi-tabbed web app. Some of these tables have columns that use formatted values. When a user clicks on the column header for these columns, the data is sorted according to the sort order of the underlying values rather than the sort order of the formatted values. This results in some cases in the data not appearing to the user to be sorted.
I'm looking for a way to fix this that can be reused across all my Tables, preferably by writing one event listener that can be attached to each Table and will handle all of the specifics regardless of the data types used in the various columns of the various associated DataTables, and regardless of whether any given column uses formatted values. I do have the condition that if any cell in a column uses a formatted value, then all of the cells in that column do, but I do not have the condition that every column uses formatted values. If a column does not use formatted values, then I want the normal sort based on the type of data in the column (e.g., number, string, date, etc.).
As an example, I could have a DataTable like the following. (This data is not actual data, but mirror situations that are problematic for me.)
var dataTable = new google.visualization.DataTable({
cols: [
{type: 'number', label: 'ID'},
{type: 'number', label: 'Places'},
{type: 'string', label: 'Things'}
],
rows: [
{c:[{v:1},{v:102735,f:'Harbor Place'},{v:'pet',f:'Dalmation'}]},
{c:[{v:2},{v:163848,f:'Alphaville'},{v:'my',f:'Top Favorites'}]},
{c:[{v:3},{v:113787,f:'Beta City'},{v:'ten',f:'Best Things'}]}
]
});
Without my doing any special configuration, this table, if sorted ascending on the ID column, would look like this, as the user would expect:
ID Places Things
----------------------------------
1 Harbor Place Dalmation
2 Alphaville Top Favorites
3 Beta City Best Things
If the user clicks on the header for the Places column, the table then looks like this, because the ascending sort is performed on the underlying numeric values:
ID Places Things
----------------------------------
1 Harbor Place Dalmation
3 Beta City Best Things
2 Alphaville Top Favorites
The user, however, expects the table to look like this:
ID Places Things
----------------------------------
2 Alphaville Top Favorites
3 Beta City Best Things
1 Harbor Place Dalmation
If the user clicks on the header for the Things column, the table would sort ascending as follows, because of the sort order of the underlying string values:
ID Places Things
----------------------------------
2 Alphaville Top Favorites
1 Harbor Place Dalmation
3 Beta City Best Things
The user is expecting this:
ID Places Things
----------------------------------
3 Beta City Best Things
1 Harbor Place Dalmation
2 Alphaville Top Favorites
I've searched on StackOverflow and on Google and haven't found any discussion of this particular situation. So I've been working on writing my own event listener, but it quickly became very involved when trying to write it as something that can be reused for any of my Tables. So am I missing something simple? Has anyone else had a situation like this and resolved it; if so, what did you do?