Page 1 of 1
Filtering out (and not printing) empty columns
Posted: Thu Oct 02, 2025 7:14 am
by Paul
This code works great for filtering out a specified column based on non-admin users:
Code: Select all
if (!nuGlobalAccess()) {
var columnIndex = 0;
nuSetBrowseColumnSize(columnIndex, 0);
nuPrintExcludeColumns([columnIndex]);
}
Might there be a similar method for filtering out (and not printing) empty columns from the Browse form?
Re: Filtering out (and not printing) empty columns
Posted: Thu Oct 02, 2025 8:52 am
by kev1n
There’s no built-in function, but creating a JS function to dynamically show or hide columns shouldn’t be too difficult. AI can definitely help with that
Re: Filtering out (and not printing) empty columns
Posted: Thu Oct 02, 2025 5:56 pm
by Paul
A search in AI has produced some code and I placed it below the code for non-globeadmin filtering like this, but I honestly have no idea how to 'massage' it for my purpose. I get no errors when logged in as globeadmin and all columns are shown. When logged in as non-globeadmin, there is no error in the console and all columns are shown.
Code: Select all
if (!nuGlobalAccess()) {
var columnIndex = 0;
nuSetBrowseColumnSize(columnIndex, 0);
nuPrintExcludeColumns([columnIndex]);
}
function hideBlankColumns(tableId) {
// Find the table element using its ID.
const table = document.getElementById(tableId);
if (!table) {
console.error(`Table with ID "${tableId}" not found.`);
return;
}
hideBlankColumns('cases');
// Get all table rows.
const rows = table.querySelectorAll('tr');
if (rows.length === 0) {
return; // No data rows to process.
}
// Determine the number of columns.
const colCount = rows[0].querySelectorAll('th, td').length;
const isColumnBlank = new Array(colCount).fill(true);
// Iterate through all table rows, skipping the header.
for (let i = 1; i < rows.length; i++) {
const cells = rows[i].querySelectorAll('td');
for (let j = 0; j < cells.length; j++) {
// Check if the cell has content. Trim whitespace for accuracy.
if (cells[j].textContent.trim() !== '') {
isColumnBlank[j] = false; // Mark column as not blank.
}
}
}
// Apply styling to hide the blank columns.
const headerCells = rows[0].querySelectorAll('th, td');
for (let j = 0; j < colCount; j++) {
if (isColumnBlank[j]) {
// Hide the column header.
if (headerCells[j]) {
headerCells[j].style.display = 'none';
}
// Hide all corresponding data cells in that column.
for (let i = 1; i < rows.length; i++) {
const cells = rows[i].querySelectorAll('td');
if (cells[j]) {
cells[j].style.display = 'none';
}
}
}
}
}
Re: Filtering out (and not printing) empty columns
Posted: Thu Oct 02, 2025 6:10 pm
by kev1n
nuBuilder tables don’t use standard <table>, <tr>, or <td> elements. Instead, they are built with <div> elements. I provided the AI with a sample output from a nuBuilder table along with your code, and this is what it generated.
Code: Select all
if (!nuGlobalAccess()) {
var columnIndex = 0;
nuSetBrowseColumnSize(columnIndex, 0);
hideBlankColumns();
nuPrintExcludeColumns([columnIndex]);
}
function hideBlankColumns() {
// Find the browse container element using its ID
const browseDiv = document.getElementById('nuRECORD');
if (!browseDiv) {
console.error(`Browse div with ID "${'nuRECORD'}" not found.`);
return;
}
// Get all browse title divs (headers)
const headers = browseDiv.querySelectorAll('.nuBrowseTitle');
if (headers.length === 0) {
console.error('No browse title headers found.');
return;
}
const colCount = headers.length;
const isColumnBlank = new Array(colCount).fill(true);
// Get all data cells (excluding empty rows)
const dataCells = browseDiv.querySelectorAll('.nuCell[data-nu-column]');
// Check each data cell to see if the column has content
dataCells.forEach(cell => {
const colIndex = parseInt(cell.getAttribute('data-nu-column'));
const content = cell.textContent.trim();
// Mark column as not blank if it has content
if (content !== '' && colIndex >= 0) {
isColumnBlank[colIndex] = false;
}
});
// Hide blank columns using nuBuilder's built-in function
for (let j = 0; j < colCount; j++) {
if (isColumnBlank[j]) {
nuSetBrowseColumnSize(j, 0);
}
}
}
To-do: exclude empty columns from printing
Re: Filtering out (and not printing) empty columns
Posted: Thu Oct 02, 2025 7:24 pm
by Paul
Yes, that code works, now to exclude from printing.
Re: Filtering out (and not printing) empty columns
Posted: Thu Oct 02, 2025 7:38 pm
by Paul
I tried adding:
Code: Select all
nuPrintExcludeColumns([colIndex]);
but no dice.
Re: Filtering out (and not printing) empty columns
Posted: Thu Oct 02, 2025 8:04 pm
by kev1n
You also need to include the columns with empty values; pass their column indexes
Re: Filtering out (and not printing) empty columns
Posted: Thu Oct 02, 2025 8:35 pm
by Paul
Ok, I tried this, but it didn't work either:
Code: Select all
if (!nuGlobalAccess()) {
var columnIndex = 0;
nuSetBrowseColumnSize(columnIndex, 0);
hideBlankColumns();
nuPrintExcludeColumns([columnIndex]);
isColumnBlank[colIndex];
nuPrintExcludeColumns([colIndex]);
}
Re: Filtering out (and not printing) empty columns
Posted: Thu Oct 02, 2025 8:52 pm
by kev1n
Try:
Code: Select all
if (!nuGlobalAccess()) {
// Get hidden columns from hideBlankColumns
const hiddenColumns = hideBlankColumns();
// Add the manually specified column index
var columnIndex = 0;
// Combine both arrays and remove duplicates
const columnsToExclude = [...new Set([columnIndex, ...hiddenColumns])];
// Exclude all columns
nuPrintExcludeColumns(columnsToExclude);
}
function hideBlankColumns() {
const hiddenColumns = [];
// Find the browse container element using its ID
const browseDiv = document.getElementById('nuRECORD');
if (!browseDiv) {
console.error(`Browse div with ID "${'nuRECORD'}" not found.`);
return hiddenColumns;
}
// Get all browse title divs (headers)
const headers = browseDiv.querySelectorAll('.nuBrowseTitle');
if (headers.length === 0) {
console.error('No browse title headers found.');
return hiddenColumns;
}
const colCount = headers.length;
const isColumnBlank = new Array(colCount).fill(true);
// Get all data cells (excluding empty rows)
const dataCells = browseDiv.querySelectorAll('.nuCell[data-nu-column]');
// Check each data cell to see if the column has content
dataCells.forEach(cell => {
const colIndex = parseInt(cell.getAttribute('data-nu-column'));
const content = cell.textContent.trim();
// Mark column as not blank if it has content
if (content !== '' && colIndex >= 0) {
isColumnBlank[colIndex] = false;
}
});
// Hide blank columns using nuBuilder's built-in function
for (let j = 0; j < colCount; j++) {
if (isColumnBlank[j]) {
nuSetBrowseColumnSize(j, 0);
hiddenColumns.push(j);
}
}
return hiddenColumns;
}
Re: Filtering out (and not printing) empty columns
Posted: Thu Oct 02, 2025 9:05 pm
by Paul
Yes! That worked quite well, thank you!
