diff --git a/app/src/protyle/render/av/col.ts b/app/src/protyle/render/av/col.ts
index d7b3161a5..01165edc1 100644
--- a/app/src/protyle/render/av/col.ts
+++ b/app/src/protyle/render/av/col.ts
@@ -2,7 +2,7 @@ import {hasClosestBlock} from "../../util/hasClosest";
import {Menu} from "../../../plugin/Menu";
import {transaction} from "../../wysiwyg/transaction";
import {fetchPost} from "../../../util/fetch";
-import {setFilter} from "./filter";
+import {getCellValue, setFilter} from "./filter";
export const getColIconByType = (type: TAVCol) => {
switch (type) {
@@ -50,7 +50,7 @@ export const updateHeader = (rowElement: HTMLElement) => {
avHeadElement.style.position = "sticky";
};
-const removeCol = (cellElement:HTMLElement) => {
+const removeCol = (cellElement: HTMLElement) => {
const blockElement = hasClosestBlock(cellElement);
if (!blockElement) {
return false;
@@ -164,11 +164,7 @@ export const showColMenu = (protyle: IProtyle, blockElement: HTMLElement, cellEl
filter = {
column: colId,
operator: "Contains",
- value: {
- [type]: {
- content: ""
- }
- }
+ value: getCellValue(type, "")
};
avData.filters.push(filter);
transaction(protyle, [{
diff --git a/app/src/protyle/render/av/filter.ts b/app/src/protyle/render/av/filter.ts
index e1d448c58..434ea9cbf 100644
--- a/app/src/protyle/render/av/filter.ts
+++ b/app/src/protyle/render/av/filter.ts
@@ -5,6 +5,40 @@ import {getColIconByType} from "./col";
import {setPosition} from "../../../util/setPosition";
import {objEquals} from "../../../util/functions";
+export const getCellValue = (colType: TAVCol, value: string) => {
+ let cellValue: IAVCellValue;
+ if (colType === "number") {
+ if (value) {
+ cellValue = {
+ number: {
+ content: parseFloat(value),
+ isNotEmpty: true
+ }
+ };
+ } else {
+ cellValue = {
+ number: {
+ isNotEmpty: false
+ }
+ };
+ }
+ } else if (colType === "text") {
+ cellValue = {
+ text: {
+ content: value
+ }
+ };
+ } else if (colType === "mSelect" || colType === "select") {
+ cellValue = {
+ mSelect: [{
+ content: value,
+ color: ""
+ }]
+ };
+ }
+ return cellValue;
+}
+
export const setFilter = (options: {
filter: IAVFilter,
protyle: IProtyle,
@@ -16,36 +50,7 @@ export const setFilter = (options: {
const menu = new Menu("set-filter-" + options.filter.column, () => {
const oldFilters = JSON.parse(JSON.stringify(options.data.filters));
let hasMatch = false;
-
- let cellValue: IAVCellValue;
- if (colType === "number") {
- if (textElement.value) {
- cellValue = {
- number: {
- content: parseFloat(textElement.value),
- isNotEmpty: true
- }
- };
- } else {
- cellValue = {
- number: {
- isNotEmpty: false
- }
- };
- }
- } else if (colType === "text") {
- cellValue = {
- text: {
- content: textElement.value
- }
- };
- } else if (colType === "select") {
- cellValue = {
- text: {
- content: textElement.value
- }
- };
- }
+ const cellValue = getCellValue(colType, textElement?.value || "");
const newFilter: IAVFilter = {
column: options.filter.column,
value: cellValue,
@@ -112,36 +117,42 @@ export const setFilter = (options: {
`;
break;
- case "select":
- selectHTML = `
+ case "mSelect":
+ options.data.columns.find((column) => {
+ if (column.id === options.filter.column) {
+ if (column.type === "select") {
+ selectHTML = `
`;
- break;
- case "mSelect":
- selectHTML = `
+ } else {
+ selectHTML = `
`;
+ }
+ return true;
+ }
+ });
break;
}
menu.addItem({
iconHTML: "",
label: ``
});
- if (colType === "select" || colType === "mSelect") {
+ if (colType === "mSelect") {
} else if (colType === "text") {
menu.addItem({
iconHTML: "",
- label: ``
+ label: ``
});
} else if (colType === "number") {
menu.addItem({
iconHTML: "",
- label: ``
+ label: ``
});
}
menu.addItem({
@@ -229,16 +240,11 @@ export const addFilter = (options: {
icon: getColIconByType(column.type),
click: () => {
const oldFilters = Object.assign([], options.data.filters);
- let cellValue = {};
- if (column.type !== "number") {
- cellValue = {content: ""};
- }
+ const cellValue = getCellValue(column.type, "");
options.data.filters.push({
column: column.id,
operator: "Contains",
- value: {
- [column.type]: cellValue
- },
+ value: cellValue,
});
transaction(options.protyle, [{
action: "setAttrView",
@@ -260,9 +266,7 @@ export const addFilter = (options: {
filter: {
operator: "Contains",
column: column.id,
- value: {
- [column.type]: cellValue
- }
+ value: cellValue
},
protyle: options.protyle,
data: options.data,