0.0.11 • Published 9 months ago

@ksgl/treegrid v0.0.11

Weekly downloads
-
License
ISC
Repository
github
Last release
9 months ago

Vue Treegrid

Deploy Teste

This component was created using the tree-grid and bootstrap-table

How to install

  1. Install npm module
npm i @ks-labs/treegrid
  1. Import module
// main.js
import Vue from "vue";
import TreeGrid from "@ks-labs/treegrid";
import "@ks-labs/treegrid/src/assets/css/jquery.treegrid.css";

Vue.use(TreeGrid);
// public/index.html
<html>
  <head>
    ...

    <link href="https://unpkg.com/bootstrap-table@1.18.3/dist/extensions/sticky-header/bootstrap-table-sticky-header.css" rel="stylesheet">
    <link href="https://unpkg.com/bootstrap-table@1.18.3/dist/bootstrap-table.min.css" rel="stylesheet"/>

    ...
  </head>
  <body>

    ...

    <script src="https://unpkg.com/bootstrap-table@1.19.1/dist/bootstrap-table.min.js"></script>
    <script src="https://unpkg.com/bootstrap-table@1.19.1/dist/bootstrap-table-vue.min.js"></script>
    <script src="https://unpkg.com/bootstrap-table@1.19.1/dist/extensions/treegrid/bootstrap-table-treegrid.min.js"></script>
    <script src="https://unpkg.com/bootstrap-table@1.19.1/dist/extensions/sticky-header/bootstrap-table-sticky-header.min.js"></script>
  </body>
</html>

How to use

<template>
  <div>
    <treegrid
      styles="table table-bordered"
      :rows="rows"
      :columns="columns"
      :rowStyle="rowStyle"
      :formatNoMatches="formatNoMatches"
      @onPostBody="onPostBody"
      @onClickRow="onClickRow"
      @headerStyle="headerStyle"
    >
    </treegrid>
  </div>
</template>

<script>
  export default {
    name: "app",
    data() {
      return {
        columns: [
          {
            field: "name",
            title: "Projeto/Área",
            align: "left",
            cellStyle: (_, body) => {
              if (body.isConsolidation) {
                return { classes: "is-line-root" };
              }
              return { classes: "name-field" };
            },
          },
          {
            field: "media",
            title: "Média",
            align: "left",
            formatter: (value, row) => {
              if (!row?.total) return "";
              return this.formatCurrency(value ?? 0);
            },
            cellStyle: () => {
              return {
                classes: "column-media",
              };
            },
          },
        ],
        rows: [
          {
            id: 154,
            media: 6098.49,
            total: 6098.49,
            january: {
              total: 6098.49,
              isProjection: false,
              hasDuplicated: {
                value: true,
                duplicated: [
                  {
                    id: 70,
                    invoice_id: 950,
                    cost_center_id: 2922,
                    vehicle_id: 552,
                    traffic_ticket_id: null,
                    billing_month: "2023-01-01",
                    cost_type: "Rental",
                    value: 2033,
                    description: null,
                    created_at: "2023-01-23 19:02:46",
                    updated_at: "2023-01-23 19:02:46",
                  },
                  {
                    id: 65,
                    invoice_id: 945,
                    cost_center_id: 2003,
                    vehicle_id: 552,
                    traffic_ticket_id: null,
                    billing_month: "2023-01-19",
                    cost_type: "Rental",
                    value: 993.29,
                    description: null,
                    created_at: "2023-01-19 17:35:24",
                    updated_at: "2023-01-19 19:49:34",
                  },
                ],
              },
            },
            name: "Gastos Gerais",
            isConsolidation: true,
          },
          {
            id: 157,
            media: 2200,
            total: 2200,
            pid: null,
            january: {
              total: 2200,
              isProjection: true,
              hasDuplicated: { value: false, duplicated: [] },
            },
            name: "Diretoria de Logística",
            isConsolidation: true,
          },
        ],
      };
    },
  };
</script>

Below are some configurations supported by the component, if you need a new configuration please open a Pull Request

Props

NameTypeDefaultDescription
RowsArrayAll table body data
ColumnsArrayAll data on column headings
idFieldStringidOverwrite the default idField to 'id'
parentIdFieldStringpidSet the parent id field.
treeShowFieldStringSet the treeShowField will auto enable the tree grid.
rootParentIdStringnullSet the root parent id.
treeEnableBooleanfalseSet true to enable the tree grid.
stickyHeaderBooleanfalseSet true to use sticky header.
clickColorStringColor displayed in the background when clicking on a line
rowStyleFunction{}The row style formatter function, takes two parameters: row, index
formatNoMatchesFunction''Set message when the rows array is empty

Events

NameDescriptionparams
onPostBodyIt fires after the table body are rendered and available in the DOM. The parameters contain:element treegrid
onClickRowIt fires when the user clicks a rowObject: {row, $element, field}
onClickCellIt fires when the user clicks a cellObject: {field, value, row, $element}
onDblClickRowIt fires when the user double clicks a rowObject: {row, $element, field}
onDblClickCellIt fires when the user double clicks a cellObject: {field, value, row, $element}
onExpandRowIt fires when you click the detail icon to expand the detail viewObject: { index, row, $detail}
onCollapseRowIt fires when you click the detail icon to collapse the detail viewObject: {index, row, detailView}
headerStyleThe header style formatter functioncolumn
0.0.11

9 months ago