mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-22 10:46:06 +02:00
merge
This commit is contained in:
commit
3d86bef4f2
1 changed files with 25 additions and 3 deletions
|
@ -5506,6 +5506,8 @@ const SORT_BUTTON = `.${SORT_BUTTON_CLASS}`;
|
|||
const SORTABLE_HEADER = `th[data-sortable]`;
|
||||
const ANNOUNCEMENT_REGION = `.${PREFIX}-table__announcement-region[aria-live="polite"]`;
|
||||
|
||||
// ---- DOTGOV EDIT
|
||||
|
||||
/** Gets the data-sort-value attribute value, if provided — otherwise, gets
|
||||
* the innerText or textContent — of the child element (HTMLTableCellElement)
|
||||
* at the specified index of the given table row
|
||||
|
@ -5514,7 +5516,19 @@ const ANNOUNCEMENT_REGION = `.${PREFIX}-table__announcement-region[aria-live="po
|
|||
* @param {array<HTMLTableRowElement>} tr
|
||||
* @return {boolean}
|
||||
*/
|
||||
const getCellValue = (tr, index) => tr.children[index].getAttribute(SORT_OVERRIDE) || tr.children[index].innerText || tr.children[index].textContent;
|
||||
const getCellValue = (tr, index) => {
|
||||
if (tr.children[index])
|
||||
return tr.children[index].getAttribute(SORT_OVERRIDE) || tr.children[index].innerText || tr.children[index].textContent;
|
||||
return "";
|
||||
}
|
||||
|
||||
// const getCellValue = (tr, index) => tr.children[index].getAttribute(SORT_OVERRIDE) || tr.children[index].innerText || tr.children[index].textContent;
|
||||
// DOTGOV: added check for tr.children[index] to protect from absent cells
|
||||
|
||||
// ---- END DOTGOV EDIT
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Compares the values of two row array items at the given index, then sorts by the given direction
|
||||
|
@ -5526,7 +5540,6 @@ const compareFunction = (index, isAscending) => (thisRow, nextRow) => {
|
|||
// get values to compare from data attribute or cell content
|
||||
const value1 = getCellValue(isAscending ? thisRow : nextRow, index);
|
||||
const value2 = getCellValue(isAscending ? nextRow : thisRow, index);
|
||||
|
||||
// if neither value is empty, and if both values are already numbers, compare numerically
|
||||
if (value1 && value2 && !Number.isNaN(Number(value1)) && !Number.isNaN(Number(value2))) {
|
||||
return value1 - value2;
|
||||
|
@ -5601,7 +5614,16 @@ const sortRows = (header, isAscending) => {
|
|||
const thisHeaderIndex = allHeaders.indexOf(header);
|
||||
allRows.sort(compareFunction(thisHeaderIndex, !isAscending)).forEach(tr => {
|
||||
[].slice.call(tr.children).forEach(td => td.removeAttribute("data-sort-active"));
|
||||
tr.children[thisHeaderIndex].setAttribute("data-sort-active", true);
|
||||
|
||||
// ---- DOTGOV EDIT
|
||||
|
||||
// tr.children[thisHeaderIndex].setAttribute("data-sort-active", true);
|
||||
if (tr.children[thisHeaderIndex])
|
||||
tr.children[thisHeaderIndex].setAttribute("data-sort-active", true);
|
||||
// DOTGOV added conditional to protect from tr.children[thisHeaderIndex] being absent
|
||||
|
||||
// ---- END DOTGOV EDIT
|
||||
|
||||
tbody.appendChild(tr);
|
||||
});
|
||||
return true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue