diff --git a/main.js b/main.js index b69ad2da..f87ab4d8 100644 --- a/main.js +++ b/main.js @@ -6,11 +6,8 @@ /** * Controls what dropdown options are visible depending on grid settings. - * @param {Object} hot Handonstable grid instance. - * @param {Object>} invalidCells See `getInvalidCells` - * return value. */ -const toggleDropdownVisibility = (hot, invalidCells) => { +const toggleDropdownVisibility = () => { $('.hidden-dropdown-item').hide(); $('#settings-dropdown-btn-group') @@ -28,11 +25,13 @@ const toggleDropdownVisibility = (hot, invalidCells) => { $('#show-all-rows-dropdown-item').show(); } - // Invalid cells present if (!jQuery.isEmptyObject(INVALID_CELLS)) { - $('#show-valid-rows-dropdown-item').show(); $('#show-invalid-rows-dropdown-item').show(); } + const validRowCount = HOT.countRows() - HOT.countEmptyRows(); + if (validRowCount > Object.keys(INVALID_CELLS).length) { + $('#show-valid-rows-dropdown-item').show(); + } }) .on('hide.bs.dropdown', () => { $('.hidden-dropdown-item').hide(); @@ -452,15 +451,17 @@ const changeColVisibility = (id, data, hot) => { * @param {Object} hot Handsontable instance of grid. */ const changeRowVisibility = (id, invalidCells, hot) => { + const rows = [...Array(HOT.countRows()).keys()]; + const emptyRows = rows.filter(row => hot.isEmptyRow(row)); let hiddenRows = []; if (id === 'show-valid-rows-dropdown-item') { - const rows = [...Array(HOT.countRows()).keys()]; - hiddenRows = Object.keys(INVALID_CELLS).map(Number); + hiddenRows = Object.keys(invalidCells).map(Number); + hiddenRows = [...hiddenRows, ...emptyRows]; } else if (id === 'show-invalid-rows-dropdown-item') { - const rows = [...Array(HOT.countRows()).keys()]; - const invalidRowsSet = new Set(Object.keys(INVALID_CELLS).map(Number)); + const invalidRowsSet = new Set(Object.keys(invalidCells).map(Number)); hiddenRows = rows.filter(row => !invalidRowsSet.has(row)); + hiddenRows = [...hiddenRows, ...emptyRows]; } HOT.updateSettings({hiddenRows: {rows: hiddenRows}}); @@ -485,7 +486,7 @@ const getInvalidCells = (hot, data) => { let valid = true; if (!cellVal) { - valid = !fields[col].requirement; + valid = fields[col].requirement !== 'required'; } else if (datatype === 'integer') { valid = Number.isInteger(cellVal); } else if (datatype === 'decimal') {