|
|
@@ -23,6 +23,7 @@ var searchTerms ={};
|
|
|
function initializeDataTable() {
|
|
|
var dataTableName = document.getElementById('datatable-config').dataset.datatableName;
|
|
|
var dataTableColumnsConfig = JSON.parse(document.getElementById('datatable-config').dataset.datatableColumnsConfig);
|
|
|
+ var dataTableHeadersConfig = JSON.parse(document.getElementById('datatable-config').dataset.datatableHeadersConfig);
|
|
|
if ($.fn.DataTable.isDataTable(`#${dataTableName}-table`)) {
|
|
|
dataTableInstance.destroy();
|
|
|
$(`#${dataTableName}-table tbody`).empty(); // Clear rows to prevent residue
|
|
|
@@ -40,8 +41,39 @@ function initializeDataTable() {
|
|
|
url: '/api/report-data/' + dataTableName,
|
|
|
type: 'POST',
|
|
|
dataSrc: function (json) {
|
|
|
- console.log('Returned rows:', json.data);
|
|
|
- return json.data;
|
|
|
+ //console.log('Returned data:', json);
|
|
|
+ //populate any dropdown headers
|
|
|
+ //console.log(dataTableHeadersConfig);
|
|
|
+ dataTableHeadersConfig.forEach(function(headerConfig, index){
|
|
|
+
|
|
|
+ if(headerConfig.searchtype == "dropdown")
|
|
|
+ {
|
|
|
+ //console.log('Tyson here');
|
|
|
+ var dropdown = $('#'+headerConfig.header.replace(' ', '-')+'FilterDropdown');
|
|
|
+ //console.log(dropdown);
|
|
|
+ dropdown.empty().append($('<option>',{
|
|
|
+ value: '',
|
|
|
+ text: '-- Select --'
|
|
|
+ }));
|
|
|
+ json.dropdowndata[index].forEach(function (option) {
|
|
|
+ var selected = false;
|
|
|
+ if(json.searchterms && json.searchterms[index]){
|
|
|
+ Object.keys(searchTerms[index]).forEach(function (key){
|
|
|
+ var searchValue = searchTerms[index][key]
|
|
|
+ console.log('value: '+searchValue)
|
|
|
+ if(option === searchValue)
|
|
|
+ {
|
|
|
+ selected = true;
|
|
|
+ }})}
|
|
|
+
|
|
|
+ dropdown.append($('<option>',{
|
|
|
+ value: option,
|
|
|
+ text: option
|
|
|
+ }).prop('selected', selected))});
|
|
|
+ }});
|
|
|
+
|
|
|
+
|
|
|
+ return json.data;
|
|
|
},
|
|
|
data: function (d) {
|
|
|
d.searchTerms = searchTerms || {};
|
|
|
@@ -90,12 +122,14 @@ function getFilterInput(searchTerm, index, searchType, extra){
|
|
|
}
|
|
|
if (extra === "start") {
|
|
|
inner[index].start = searchTerm;
|
|
|
- console.log("start date: ");
|
|
|
}
|
|
|
else if (extra === "end") {
|
|
|
inner[index].end = searchTerm;
|
|
|
}
|
|
|
break;
|
|
|
+ case "dropdown":
|
|
|
+ inner[index] = searchTerm;
|
|
|
+ break;
|
|
|
}
|
|
|
searchTerms[index] = inner;
|
|
|
console.log(searchTerms[index]);
|