linmasahiro / vue3-table-lite

A simple and lightweight data table component for Vue.js 3. Features sorting, paging, row check, dynamic data rendering, supported TypeScript, and more.
https://vue3-lite-table.vercel.app/
MIT License
248 stars 73 forks source link

Could not find a way to change the route of the app using the buttons on table #102

Open lucafs opened 11 months ago

lucafs commented 11 months ago
      {
        label: "",
        field: "quick",
        width: "5%",
        display: () => {
            # needed a button here to change route here
        },
    },

Tried several different things and could not find a way to do it.. Can you help me?

linmasahiro commented 11 months ago

Hi, @lucafs , here is example.

  1. return an element on display function.
    {
    label: "",
    field: "quick",
    width: "5%",
    display: (row) => {
     return "<button id='is-rows-el redirect-btn' data-xx='" + row.xx + "'>redirect</button>"
    },
    }
  2. add button click event to tableLoadingFinish function
    const tableLoadingFinish = (elements) => {
      table.isLoading = false;
      Array.prototype.forEach.call(elements, function (element) {
        if (element.classList.contains("redirect-btn")) {
          element.addEventListener("click", function () {
            const xx = this.dataset.xx;
            // add your route change code
          });
        }
      });
    };