mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Allow filtering by selected cell value in cell context menu
Summary: Adds a command and `BaseView` method `filterByThisCellValue`. Test Plan: Added two tests to `nbrowser/CellContextMenu.ts` Reviewers: georgegevoian Reviewed By: georgegevoian Differential Revision: https://phab.getgrist.com/D3383
This commit is contained in:
@@ -229,6 +229,8 @@ BaseView.commonCommands = {
|
||||
insertCurrentDateTime: function() { this.insertCurrentDate(true); },
|
||||
|
||||
copyLink: function() { this.copyLink().catch(reportError); },
|
||||
|
||||
filterByThisCellValue: function() { this.filterByThisCellValue(); },
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -305,6 +307,26 @@ BaseView.prototype.copyLink = async function() {
|
||||
}
|
||||
};
|
||||
|
||||
BaseView.prototype.filterByThisCellValue = function() {
|
||||
const rowId = this.viewData.getRowId(this.cursor.rowIndex());
|
||||
const col = this.viewSection.viewFields().peek()[this.cursor.fieldIndex()].column();
|
||||
let value = this.tableModel.tableData.getValue(rowId, col.colId.peek());
|
||||
|
||||
// This mimics the logic in ColumnFilterMenu.addCountsToMap
|
||||
// ChoiceList and Reflist values get 'flattened' out so we filter by each element within.
|
||||
// In any other column type, complex values (even lists) get converted to JSON.
|
||||
let filterValues;
|
||||
if (gristTypes.isList(value) && gristTypes.isListType(col.type.peek())) {
|
||||
filterValues = value.slice(1);
|
||||
} else {
|
||||
if (Array.isArray(value)) {
|
||||
value = JSON.stringify(value);
|
||||
}
|
||||
filterValues = [value];
|
||||
}
|
||||
this.viewSection.setFilter(col.getRowId(), JSON.stringify({included: filterValues}));
|
||||
};
|
||||
|
||||
/**
|
||||
* Insert a new row immediately before the row at the given index if given an Integer. Otherwise
|
||||
* insert a new row at the end.
|
||||
|
||||
@@ -384,6 +384,15 @@ exports.groups = [{
|
||||
},
|
||||
|
||||
],
|
||||
}, {
|
||||
group: 'Filtering',
|
||||
commands: [
|
||||
{
|
||||
name: 'filterByThisCellValue',
|
||||
keys: [],
|
||||
desc: `Filter this column by just this cell's value`,
|
||||
},
|
||||
]
|
||||
}, {
|
||||
group: 'Linking',
|
||||
commands: [
|
||||
|
||||
Reference in New Issue
Block a user