New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

admin-table-page

Package Overview
Dependencies
Maintainers
0
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

admin-table-page

An admin table page component based on vue3 and element-plus

latest
Source
npmnpm
Version
1.0.3
Version published
Maintainers
0
Created
Source

Admin Table Page

Chinese

Admin Table Page component based on Vue3.js and Element-plus

  • Write a table page with search fields, toolbar and pagination functions by simple configure
  • Only need a promise function that fetchs data from the server to automatically complete the table data pulling and rendering
  • Support automatic refresh and manual refresh of the table data when fetching data from the server
  • Automatically pagination
  • Select rows on different pages even when fetching data from the server
  • When search fields or pagination changed, the table datas will be loaded automatically
  • Customize each part of the component through different named slot
  • Support Chinese and English language
  • Adaptive layout for different device

Issue Reporting

If you have found a bug, please report it in this issues section. Thanks!

Local Demo

npm install / yarn install
npm run dev / yarn run dev

Open http://localhost:8173 to see the demo

Installation

NPM

npm install admin-table-page

Yarn

yarn add admin-table-page

Usage

Global Scope

import AdminTablePage from "admin-table-page";

// Only one of the following two style files needs to be imported

// If you don't want to change the theme of element-plus, import like this:
import "admin-table-page/lib/style.css";
// If you custom your element-plus theme, import like this:
import "admin-table-page/style/index.scss";

import { createApp } from "vue";

const app = createApp(...);
app.use(ConfigTable);

VUE SFC Component

<template> 
  <admin-table-page
    :columns="columns"
    :fetch-method="getDataApi"
    :tool-buttons="toolButtons"
    :refresh="5000"
    :action-column="actionColumn"
    selectable="multiple"
    row-key="id"
  />
</template>

<script setup>
import { AdminTablePage } from "admin-table-page";
// Only one of the following two style files needs to be imported
// If you don't want to change the theme of element-plus
import "admin-table-page/lib/style.css";
// If you custom your element-plus theme
import "admin-table-page/style/index.scss";

const columns = [{
  prop: "name",
  label: "Name",
  filterable: true
}, {
  prop: "age",
  label: "Age",
  filterOptions: {
    type: "select",
    options: ["Under 10 years old", "10 to 20 years old"]
  }
}];

const toolButtons = [{
  text: "New Record",
  icon: "Plus",
  onClick: handleAdd
}]

const actionColumn = [{
  text: "Edit",
  onClick: row => handleEdit(row)
}, {
  text: "Delete",
  onClick: row => handleDelete(row)
}]

const getDataApi = () => {
  return new Promise((resolve, reject) => {
    resolve({
      total: 2,
      list: [{
        name: "name1",
        age: 1
      }, {
        name: "name2",
        age: 2
      }]
    })
  })
}

</script>

Then, you can get a page like this:

Demo

Props

PropsDescriptionTypeAccepted ValuesDefault Value
columnsThe defination of the table's columns.
In addition to the original attributes of el-table-column, use filterable or filterOptions to define the filtering of the column Filter
array-[]
local-dataThe local table data, same as ElTalbe's data propertyarray-[]
total-keyTo map the key for total count in the result when fetch datas from remote.string-"total"
list-keyTo map the key for data list in the result when fetch datas from remote.string-"list"
fetch-methodThe method to get the table data from remote server(query: object) => Promise<{totalKey: number, listKey: array}>--
refreshHow to refresh the table datastring/numberstring value:
"" - Never to refresh Table
"manual" - Refresh table data manually"
number value:
Table refresh period with milliseconds. For example,:refresh="5000"
""
tool-buttonsToolbar buttons. Toolbar button Attributesarray--
show-indexDisplay the index of the row when it's true.booleanfalse
true
false
row-keySame as el-table, it's required when set selectable to "single" or "multiple"string--
selectableHow to select the rows in table.boolean/stringstring value:
"single" - single select
"multiple" - multiple select
boolean value:
false: not suppor selection
false
localei18n locale configstring"zhCn", "en""zhCn"
action-columnThe action column shown in each row.array--
action-column-labelThe label of action columnstring-en - "Actions"
zhCn - "操作"
extra-queryThe extra query params need to send to server when fetch datas from remote.object--
el-pagination-propsOther el-pagination Attributesobject--
tipstips string for the table.string--

In addition, other attributes of el-table can fallthrough.

Method

FunctionDescriptionType
reloadReload the table data. You can pass other parameters besides searchFields and pagination parameters(params) => void
getSelectionsReturn the selected rows or seleted row object. When multiple selecting, you can get the selected rows on different pages.() => array or object

In addition, all methods of el-table are alse suppored.

Events

EventDescriptionParameters
select-changetriggers when selection change.
Returns a row Object when selectable is "single".
Returns rows Array when selectable is "multiple"
row/rows

Custom Slots

NameDescription
searchThe search
toolsThe toolbar
actionsThe action column
actions_headerThe header of the action column
tipsThe tips of the table
extra_columnsExtra customed columns
[column.prop]Each column can be customed by slot named with the column's prop
[column.prop]_headerThe header of column can be customed by named slot

Toolbar Buttons

AttributesRequiredDescriptionTypeDefault Value
texttrueThe text displayed on the button.String-
onClicktrueThe callback function for click events.Function-
showfalseWhether to display the button. Default is true.Booleantrue

In addition, all attributes for el-button are supported. For example,

const toolButtons = [{
  text: "test button",
  onClick: () => { console.log("it's toolbar button")},
  icon: "Plus",
  type: "danger",
  link
}]

Filter

Only support el-input、el-select and el-date-picker(type="date") for search components.

You can set filterable or filterOptions for each element in the array defined by columns.

  • filterable is a boolean value. You can get a el-input filter component for the column when it's true.
  • filterOptions is an object. You can set other properties for the filter component like defaultHidden to set whether it's hidden by default, or use other types of filter components we support.

Attributes of filterOptions

AttributesTypeRequiredDescriptionAccepted ValueDefault
typestringfalseThe type of the search field."input"
"select"
"date"
"input"
defaultHiddenbooleanfalseWhether this filter component is hidden by default.true
false
false
optionsarrayfalseThe select options.
It's required when type is "select". The element for options Array can be string、number or object with keys named label and value.
["options1", "options2",...]
or
[{ label: "option1", value: "option1" }]
-

In addition, all attributes for el-input/el-select/el-date-picker(type="date") are supported. For example,

const columns = [{
  prop: "username",
  label: "Username",
  filterable: true
}, {
  prop: "age",
  label: "Age",
  filterOptions:{
    type: "select",
    options: ["18", "19"],
    defaultHidden: true
  }
}]

Keywords

vue3

FAQs

Package last updated on 31 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts