How To Identify DataGrid2 Filter Attribute In JavaScript
0
Hi all, I want to display the number of lines for a DataGrid2, when having virtual scrolling. I have managed to display the number of lines currently displayed. However, when I attempt to display the total lines (i.e. lines available and not necessarily displayed), I struggle with implementing the filters. My JavaScript look as follows: export async function JS_DisplayNumberOfProjects(textWigetName, dataGrid2WidgetName) { // BEGIN USER CODE // Get elements for DataGrid2 and text widget const dataGridElement = document.querySelector(`.mx-name-${dataGrid2WidgetName}`); const textWidgetElement = document.querySelector(`.mx-name-${textWigetName}`); if (!dataGridElement || !textWidgetElement) { console.warn("DataGrid2 or Text widget element not found."); return; } // Function to construct XPath with filters function buildXPathFromDataGrid(grid, entityName) { const filters = grid.querySelectorAll(".filter-container"); const xpathConditions = []; filters.forEach(filter => { let attribute = filter.getAttribute("data-mendix-attribute"); if (!attribute) return; const textInput = filter.querySelector("input.form-control:not(.dropdown-triggerer)"); const dropdownInput = filter.querySelector("input.dropdown-triggerer"); if (textInput && textInput.value.trim()) { xpathConditions.push(`contains(${attribute}, '${textInput.value.trim()}')`); } else if (dropdownInput && dropdownInput.value.trim()) { const values = dropdownInput.value.split(",").map(v => v.trim()); const orConditions = values.map(v => `${attribute}='${v}'`).join(" or "); xpathConditions.push(`(${orConditions})`); } }); return `//${entityName}${xpathConditions.length ? `[${xpathConditions.join(" and ")}]` : ""}`; } // Function to get the total row count async function getTotalRows() { const xpath = buildXPathFromDataGrid(dataGridElement, "Module.Entity"); console.log(`Generated XPath: ${xpath}`); return new Promise((resolve, reject) => { mx.data.get({ xpath: xpath, callback: objs => resolve(objs.length), error: error => reject(error), }); }); } // Function to update row count display async function updateRowCount() { try { const totalRows = await getTotalRows(); const visibleRows = dataGridElement.querySelectorAll(".mx-grid-row").length; textWidgetElement.innerText = `Records: ${visibleRows} of ${totalRows}`; } catch (error) { console.error("Error fetching total rows:", error); } } // Monitor for changes in DataGrid2 const observer = new MutationObserver(updateRowCount); observer.observe(dataGridElement, { childList: true, subtree: true }); // Initial count update updateRowCount(); // END USER CODE } The result of the XPath is: //Module.Entity[[contains(unknownAttribute, 'My Sample Value')]] Any help would be appreciated