Hi Jean,
As an alternative solution, you can combine your solution with my suggestion.
You can create a function and attach it to the event On Show ot the dataview, and you add a delay until the elements are rendered on the screen.
This function will inject an event trigger in the rows, and by selecting the row, you can trigger the button you created (you must have the button because the hidden values you need will be only available when a function is triggered from five).
This button will have an On Click function with your functionality.
Therefore, you can click on any row, and it will automatically click on the button you created.
This is the function added to the On Show event of the dataview.
function TargetRowsDataviews(five, context, result) {
console.log('TargetRowsDataviews')
function enableRowButtonClick() {
console.log('TargetRowsDataviews')
// Wait 1 second for elements to render
setTimeout(() => {
// First verify Five-ListView exists
const listView = document.getElementById('Five-ListView');
if (!listView) {
console.log('Five-ListView not found');
return;
}
// Verify if one of its child elements contains 'ProductSQL View'
const hasProductSQLView = Array.from(listView.querySelectorAll('*'))
.some(el => el.textContent.includes('ProductSQL View'));
// Stop process if text does not exist
if (!hasProductSQLView) {
console.log('ProductSQL View not found');
return;
}
// Only now verify the grid exists
const grid = document.getElementById('virtual-table-grid-div');
if (!grid) {
console.log('Grid not found');
return;
}
console.log('ProductSQL View found - adding event listener');
// Add click listener to the grid
grid.addEventListener('click', function (event) {
// Find clicked row
const row = event.target.closest('[role="row"]');
if (!row) return;
// Prevent duplicate execution if button itself was clicked
if (event.target.closest('button')) return;
// Find button inside row
const button = row.querySelector('button');
// Trigger button click
if (button) {
button.click();
}
});
}, 1000);
}
// Initialize
enableRowButtonClick();
return five.success(result);
}
This is the function that runs when the button is clicked.
function NavigateProductRecord(five, context, result) {
five.selectAction('Products', five.field.ProductKey)
return five.success(result);
}
This is my dataview with a button in the first column, like your example:
Basically, instead of clicking on the button to execute the function, I click on any row, and it will automatically click on the button for that row to execute the function for me.
Workflow:
-
Wait 1 second for rendering.
-
Check if Five-ListView exists.
-
Verify if it contains the text ProductSQL View. This is the name of my dataview (you must change it to yours).
-
Only if the text exists:
-
Clicking a row automatically triggers the row button.
Regards,
Elton S