要約
- Tabulatorで編集可能なtickCrossを使用する際には、editorプロパティを設定しない
Tabulator公式サンプル
Editing Data | Tabulator
上記の公式サイトの記述に合わせて、formatter:"tickCross"
のColumsにedtor:true
を設定すると、クリック時に表示が崩れます。
bad sample
{
title: "Approved",
field: "approved",
hozAlign: "center",
formatter: "tickCross",
width: 150,
editor: true,
formatterParams: {
tickElement:
'<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" class="lucide lucide-circle-check"><circle cx="12" cy="12" r="10"/><path d="m9 12 2 2 4-4"/></svg>',
crossElement:
'<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" class="lucide lucide-circle"><circle cx="12" cy="12" r="10"/></svg>',
},
},
formatterParamsを使用していない公式サンプルでも再現しています。
解決方法
edtorプロパティを設定せず、cellClickで切り替えます。
good sample
{
title: "Approved",
field: "approved",
hozAlign: "center",
formatter: "tickCross",
width: 150,
- editor: true,
+ cellClick: (e, cell) => {
+ const newValue = !cell.getValue();
+ cell.setValue(newValue, true);
+ },
formatterParams: {
tickElement:
'<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" class="lucide lucide-circle-check"><circle cx="12" cy="12" r="10"/><path d="m9 12 2 2 4-4"/></svg>',
crossElement:
'<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" class="lucide lucide-circle"><circle cx="12" cy="12" r="10"/></svg>',
},
},
公式issueでも推奨されているアプローチです。
tickCross editing · Issue #341 · olifolkerd/tabulator
I would recommend that you don't use an editor but instead use the cellClick function and the getValue and setValue functions on the cell component: