Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spaces in metric labels causes exception when rendering a row or column_index_table in Datatables.net #13

Closed
mikeengland opened this issue Aug 15, 2016 · 1 comment
Assignees
Milestone

Comments

@mikeengland
Copy link
Contributor

The JSON returned when using the row_index_table or column_index_table managers returns data in a label: value format.

This causes issues with the datatables.net API as space characters may appear in the column name e.g. 'exchange rate'. When mapping the columns to a table in datatables, having spaces in the column name causes the data table to raise an exception as can be seen from the fizz buzz column below.

Example JSON returned from FireAnt:

{ "draw": 1, "data": [ { "foo": 12.1111 "bar": "1.1", "fizz buzz": 123, "DT_RowId": "row_0" }, { "foo": 12.1111 "bar": "1.1", "fizz buzz": 123, "DT_RowId": "row_1" }, ], "recordsFiltered": 2, "recordsTotal": 2 }

Example of column indexes to the columns found in the data:
$(#test).DataTable({ displayLength: 25, search: false, lengthMenu: [[10, 25, 50, 100, -1], [10, 25, 50, 100, 'All']], orderCellsTop: true, filtering: true, destroy: true, data: data, order: [0, 'desc'], columns: [ {data: 'foo'}, {data: 'bar'}, {data: 'fizz buzz'} ], ...

The exception returned is jquery.js:8264 Uncaught (in promise) TypeError: Cannot convert a Symbol value to a string(…).

There are a few solutions to how we could overcome this.

  1. Ensure each JSON key for a column value has no spaces e.g. "fizz_buzz": 5. Users will have to work out a human friendly name for each column's header programatically.
  2. Ensure each JSON key for a column value has no spaces e.g. "fizz_buzz": 5, but a label field in the nested data that a user can use to dynamically create a header column with a friendly name. e.g. "fizz_buzz": {"label": "Fizz Buzz", "value": 5}. Example at: https://datatables.net/examples/ajax/orthogonal-data.html
  3. Return data using an array of arrays instead of an array of objects. Then the user can either work out what header should map to an array index or maybe FireAnt could pass an array which defines a label for each column, which could then be used by the user to set a human friendly header. Example at: https://datatables.net/examples/ajax/simple.html.
@twheys twheys self-assigned this Aug 16, 2016
@twheys twheys added this to the 0.0.12 milestone Aug 16, 2016
@twheys
Copy link
Contributor

twheys commented Aug 16, 2016

Ok, I will change the response of the data tables transformer to provide the whole datatables JSON instead of just the data, then it can be implemented according to this post: https://datatables.net/forums/discussion/29260/dynamic-column-headers-via-ajax

@twheys twheys closed this as completed Aug 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants