Table Sort - set specific column types for better sorting Follow
When setting a table in a visualizer page we have the option to mark some columns as "Sortable".
BY default all table column are considered to be "text" columns for the sort purposes. This might not work well for columns that holds number or date values. Alphanumeric sorting in such cases will result in faulty order.
To resolve this issue you need to specify for each column of the table the exact nature of its data content. That is whether the type is a number, date etc. This can be done by adding the following section to the page code in the JavaScript editor.
Events.tableConfigure = function(config){
config.columnDefs= [
{
targets: 0,
type: 'num-fmt'
},
{
targets: 1,
type:'date'
},
{
targets: 2,
type: 'string'
},
...
]
return config;
};
The "targets" attribute refer to the column index (starting from 0).
Look here for the full list of data types.
You only need to define columns of non-string type as "string" is the default type.
Please note that if you change the table (add columns, remove, re-order) you must also update your configuration accordingly to fit the new column indexes.
Comments
0 comments
Please sign in to leave a comment.