Can I extract unique values from a returned data object?
Can I extract unique values from a returned data object?
My application has a Select, based on the unique values of a data column.
I am extending my application and will now use a column that returns a list of objects like this:
locations: [
{
location1_id: { id: 59, location_name: 'London' }
location2_id: { id: 28, location_name: 'Liverpool' }
}
This list will always hold at least a single record in the object.
It may hold two or more.
Is there a way to select the unique values from all the objects, in order that the Select would find all records where the first or second location = Liverpool?
Thanks, Tony
Answers
Hi Tony,
I'm not clear on how this will be used with DataTables. Do you want to show that information in a DataTable? What is the Select you mention. Is that a
<select>
element inside Editor?Allan
Hi Allan,
I have a Column Select, but it's located above the table - code shown below. This Select is working fine, on a column with a single data item (which may or may not exist).
However, I want to upgrade this select, so that it handles data which is an array of json objects.
The current data looks like this:
This is the DT API that builds the select for the current data.
The data coming in is now in a JSON array of objects, because the user could have zero, one or many clubs. It looks like this:
My question was: how to enhance the current code, so as to the unique values from this column, into a select.
Many thanks,
Tony
Use
column().index()
, in an if statement, to check for the column that you want to process the select list differently. For example:You might need to use Orthogonal data to set the
filter
value to match what you place in the select list.If you need help with this then please build a simple example that has a sample of your data and provide specific details of how you want the select list built.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin