Get all unique data in a column

Get all unique data in a column

LearcoLearco Posts: 5Questions: 2Answers: 0

Hello,

I'm using datatable in my js files and I would like to get all unique data in a specific column.
This is my code :

return $(tableSelector).DataTable().column(colSelector).data().unique()

It works fine but the return object does not contain only the cell values (strings), but also a lot of different functions :

data: D(4)
0: "Other"
1: "Private for-profit entities (excluding Higher or Secondary Education Establishments)"
2: "Research Organisations"
3: "Not defined"
$: ƒ ()
ajax: {__dt_wrapper: true, json: ƒ, params: ƒ, reload: ƒ, url: ƒ}
cell: ƒ ()
cells: ƒ ()
clear: ƒ ()
column: ƒ ()
...

How I am supposed to get only the cell values (first 4 items in the object) ?

Thanks.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949
    Answer ✓

    The unique() API returns an API instance along with the array of data. You can chain the toArray() API to get just the Javascript array.

    Kevin

  • LearcoLearco Posts: 5Questions: 2Answers: 0

    It worked, perfect thank you !

Sign In or Register to comment.