Combine two columns in to one value for dropdown?
Combine two columns in to one value for dropdown?
pacificshack
Posts: 1Questions: 1Answers: 0
Hi,
I have a datatable I use for sorting out listings. I have a table which has two columns for:
- From
- From2
These columns contain different data which I need to combine.
In my JS, I am able to pass through the first column OK, and some of the data from the second column, but not all of it.
How can I combine the data from both fields in to one, and the net result being a dropdown menu with both values?
$(document).ready(function() {
// var for data tables filtering
var oTable = $('#dt_basic_filtering').DataTable({
"sPaginationType": "full_numbers",
"iDisplayLength" : 25,
"bSort": true,
"aaSorting": [],
"columns": [
{ name: 'from' },
{ name: 'from2' },
{ name: 'table' }
]
});
// Create selects in footer of table
$("#dt_basic_filtering tfoot th.select").each( function ( i ) {
if ($(this).hasClass('selectFrom')) {
var select = $('<select><option class="start" value="">- Select all -</option></select>')
.appendTo( $(this).empty() )
.on('change', function () {
var val = $(this).val();
oTable.column( 'from2:name' ).search( val ? ''+$(this).val()+'' : val, true, false )
.draw();
});
}
if ($(this).hasClass('selectFrom2')) {
var select = $('<select><option class="start" value="">- Select all -</option></select>')
.appendTo( $(this).empty() )
.on('change', function () {
var val = $(this).val();
oTable.column(i).search( val ? '^'+$(this).val()+'$' : val, true, false )
.draw();
});
}
oTable.column( i ).data().unique().sort().each( function ( d, j ) {
select.append( '<option class="hasValue" value="'+d+'">'+d+'</option>' );
} );
});
// Hide second from field
$("#dt_basic_filtering tfoot th.selectFrom2 select").addClass('hidden');
});
This discussion has been closed.