import { Grid } from "gridjs/dist/gridjs.umd.js"; import gridjs from "gridjs/dist/gridjs.umd.js"; import "gridjs/dist/gridjs.umd.js"; import GlobalConfig from "../global-config"; class CommonTable { init() { // this.CommonTableInit(); this.CommonTableInitWithFetchApi(); } CommonTableInitWithFetchApi() { fetch(`${GlobalConfig.apiHost}/api/users`) .then((response) => response.json()) .then((data) => { console.log("check log response"); console.log(data.data); new Grid({ columns: [ { name: "id", formatter: function (cell) { return gridjs.html( '' + cell + "" ); }, }, "name", { name: "email", formatter: function (cell) { return gridjs.html( '' + cell + "" ); }, }, "position", "firstname", "lastname", { name: "Actions", width: "120px", formatter: function (cell) { return gridjs.html(`
`); }, }, ], pagination: { limit: 10, }, sort: true, search: true, data: data, }).render(document.getElementById("common-table")); }) .catch((error) => console.error("Error fetching data: " + error)); } } document.addEventListener("DOMContentLoaded", function (e) { new CommonTable().init(); });