1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

TabulatorのtickCrossにeditorを指定しない

Posted at

要約

  • 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>',
      },
    },

tickCross_bad_sample.gif

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>',
      },
    },

tickCross_good_sample.gif

公式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:

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?