Skip to content

Commit

Permalink
Do not show empty valid rows on toggle (#19)
Browse files Browse the repository at this point in the history
* Do not show empty rows when showing valid rows

* Also allow recommended fields to be empty

* Bug fix
  • Loading branch information
ivansg44 authored Jun 2, 2020
1 parent e49b6bb commit cc37dea
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@

/**
* Controls what dropdown options are visible depending on grid settings.
* @param {Object} hot Handonstable grid instance.
* @param {Object<Number, Set<Number>>} invalidCells See `getInvalidCells`
* return value.
*/
const toggleDropdownVisibility = (hot, invalidCells) => {
const toggleDropdownVisibility = () => {
$('.hidden-dropdown-item').hide();

$('#settings-dropdown-btn-group')
Expand All @@ -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();
Expand Down Expand Up @@ -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}});
Expand All @@ -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') {
Expand Down

0 comments on commit cc37dea

Please sign in to comment.