Get all unique data in a column
Get all unique data in a column
Learco
Posts: 5Questions: 2Answers: 0
in DataTables
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
The
unique()
API returns an API instance along with the array of data. You can chain thetoArray()
API to get just the Javascript array.Kevin
It worked, perfect thank you !