Alohajoe5 wrote:kev1n,
Like I said, the issue is that all columns are inheriting the same array of items for their drop down menu.
Thanks!
This is not a surprise, since you always pass the same values - getWords() - to the function addBrowseTitleDropDown()
To change this, you need to make modifications to the PHP function. You must write a function for each value list.
So the PHP code is going to look like this (verify the SQL statements):
Code: Select all
function sqlWords() {
return "SELECT DISTINCT word FROM MuxSignals";
}
function sqlNumbers() {
return "SELECT DISTINCT number FROM MuxSignals";
}
function sqlOffsets() {
return "SELECT DISTINCT offset FROM MuxSignals";
}
function sqlChannels() {
return "SELECT DISTINCT channel FROM MuxSignals";
}
function getBase64JsonArray($sql) {
$result = nuRunQuery($sql);
$a = array();
$a[] = ""; // add an empty value
while ($row = db_fetch_row($result)) {
$a[] = $row;
}
sort($a);
return base64_encode(json_encode( $a ));
}
$words = getBase64JsonArray(sqlWords());
$numbers = getBase64JsonArray(sqlNumbers());
$channels = getBase64JsonArray(sqlChannels());
$offsets = getBase64JsonArray(sqlOffsets());
$js = "
function getWords() {
return atob('$words');
}
function getNumbers() {
return atob('$numbers');
}
function getChannels() {
return atob('$channels');
}
function getOffsets() {
return atob('$offsets');
}
";
nuAddJavascript($js);
Then the Javascript code:
Code: Select all
if (nuFormType() == 'browse') {
var arrWords = JSON.parse(getWords());
addBrowseTitleDropDown(3, arrWords); // add dropdown to column 4 (index 3)
var arrNumbers = JSON.parse(getNumbers());
addBrowseTitleDropDown(4, arrNumbers);
var arrOffsets = JSON.parse(getOffsets());
addBrowseTitleDropDown(5, arrOffsets);
var arrChannels = JSON.parse(getChannels());
addBrowseTitleDropDown(10, arrChannels);
}
// Function to add a dropdown to a title of a Browse Screen
// * @param {number} index - browse index where the dropdown should appear
// * @param {object} data - array to populate the dropdown
function addBrowseTitleDropDown(index, data) {
var dropId = "nuBrowseTitle" + index + "_dropdown";
var list = document.createElement('select');
list.setAttribute("id", dropId);
var w = nuCurrentProperties().column_widths[index] - 10;
list.setAttribute('style', 'width:'+ w +'px');
for (var i = 0; i < data.length; i++) {
var opt = document.createElement('option');
opt.innerHTML = data[i];
opt.value = data[i];
list.appendChild(opt);
}
// append select to the browse title
$('#nuBrowseTitle'+index).append('<br/>').append(list);
$('#'+dropId).on('change', function (e) {
// var optionSelected = $("option:selected", this);
nuSetProperty(this.id,this.value);
nuSearchAction(1);
});
$('#nuBrowseTitle'+index).on('mousedown' , '> select' , function(e){
e.stopPropagation();
});
var dropValue = nuGetProperty(dropId);
$("#"+dropId).val(dropValue);
}
Browse SQL: leave unchanged.