npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mconnect/mc-data-table

v0.2.1

Published

mConnect DataTable UI Component

Downloads

5

Readme

@mconnect/mc-data-table | mConnect DataTable UI Component (vue-UI component)

  • Smart, Simple & Versatile UI datatable, built using vue3 composition API

  • Include paging of batch records and query skip-limit to load records from backend API server / service providers

  • Adjustable paging size

  • Easy search to view records by search keywords

  • Clear message showing the records view by query records and search keywords

  • Documentation In progress

Installation

npm install @mconnect/mc-data-table
// import (include) the mc-data-table stylesheet in your application
import "@mconnect/mc-data-table/dist/style.css"

Components and Features

  • screen short
  • McDataTable: entry point for defining the table options, structure and contents
  • McExplorerDataTable: McDataTable subcomponent for McExplorer component (see McExplorer for details)
  • McPageLimit: select the records to display per page [10, 20, 30, 50, 100, 200]
  • McPageNav: page navigation features - first, last, previous, next and subset of intermediary pages
  • McTable: The table structure (column / headers) and contents
  • McTableMessage: indicate the current table records information, by page navigation and records total
  • McTableNoData: a component to display when there are no records to display
  • McTableSearch: used to filter table contents/records, by search keyword(s)

Usage Specifications

  • You may import McDataTable, McExplorerDataTable & McTableNoData as components into your UI view/page
  • Dependencies: vue and w3-css
import {McDataTable, McTableNoData} from "@mconnect/mc-data-table";
import type {DataField, DataFetchAlertResult} from "@mconnect/mc-data-table"
  • activate the mcDatatable component in your UI template, and provide the required and/or optional props

<template>
  <McDataTable v-if="dataItems.length > 0" :data-fields="dataFields" :data-items="dataItems" :data-stats="dataStats"
               :data-fetch-alert="dataFetch"></McDataTable>

</template>

<script setup lang="ts">
  import { McDataTable, McTableNoData } from "@mconnect/mc-data-table";
  import type { DataField, DataFetchAlertResult, ObjectType } from "@mconnect/mc-data-table"
  import { computed, ref } from "vue"
  import { GetRecordStats } from "./types";

  // McDataTable props
  // dataItems => records to be displayed in the mc-table | from API read request
  const dataItems = Array<ObjectType>([])
  const dataStats: GetRecordStats = ref({
    
  })
  const fetchAlertResult = ref<DataFetchAlertResult>({})

  // Data may be fetch in batches for table-records view
  // sample dataFetch for the next skip-limit records
  const dataFetch = async (val: DataFetchAlertResult) => {
    // store fetchAlertResult
    fetchAlertResult.value = val
    // perform the required read-query task using the skip and limit values from val(DataFetchAlertResult)
    if (val.fetchAlert) {
      await appStore.getAppRequest({
        skip : val.skip,
        limit: val.limit,
      })
    }
  }
  
  // McExplorerDataTable props, in addition to McDataTable


  // McTableNoData props
  // dataItems count
  // const itemsCount = ref(dataItems.length)
  const itemsCount = computed(() => {
    return dataItems.length
  })

  // Helper methods
  const isProcessing = ref(false)   // use to deactive the save-button when an active transaction is in progress
  const isMessage = ref(false)
  const pageMessage = ref("")       // to set the messages for the componenent tasks
  const itemId = ref("")    // current record ID, for update task
  const itemsIds = ref<Array<string>>([])   // for delete task
  const addItemId = (ids: Array<string>) => {
    itemsIds.value = ids
  }
  const activeLabel = (isActive: boolean) => {
    return isActive
            ? `<span>${labels.yes} <i class="fa fa-check"></i></span>`
            : `<span>${labels.no} <i class="fa fa-power-off"></i></span>`
  }
  const updateItem = async (itemRec: AppType) => {
    // Route to detail page
    await router.push({name: "appDetail", params: {itemId: itemRec.id || ""}});
  }

  const deleteResponse = async (res: RESTAPI-UserDefined_Type) =>
  {
    // handle the deleteRecord request API response
  }

  const deleteItem = async (itemId: string) => {
    isMessage.value = false;
    pageMessage.value = "";
    if (!itemId) {
      isMessage.value = true;
      pageMessage.value = "Item-ID is required to proceed";
      return;
    }
    // perform delete/remove action
    if (confirm(messages.confirmDelete)) {
      isProcessing.value = true
      isMessage.value = true;
      pageMessage.value = "Removing record.......";
      // API delete request (using axios/request helper deleteRecord function)
      const crudParams: CrudParamsType = {
        recordIds  : [itemId],
        queryParams: {},
      }
      const res = await deleteRecord(apiPaths.APP_DELETE, crudParams);
      // response
      await deleteResponse(res);
    } else {
      isProcessing.value = false
    }
  }

  // dataFields specified the specification to construct mc-data-table table header/columns and row-columns value
  // See types definition for DataField to understand the meaning of the mandatory and optional? fields
  const dataFields: Array<DataField> = [
    {
      name   : "select",
      label  : "Select",
      type   : "boolean",
      default: false,
      order  : 1,
      sort   : false,
      source : {
        type   : "checkbox",
        task   : addItemId,
        params : ["id"],
        data   : [],
        bind   : itemsIds.value,
        domComp: false
      },
      events : [{type: "change", task: addItemId, params: ["id"]}]
    },
    {
      name   : "appName",
      label  : "Application",
      type   : "string",
      default: "N/A",
      order  : 2,
      sort   : true,
      source : {type: "provider"},
    },
    {
      name   : "appTag",
      label  : "Application Tag",
      type   : "string",
      default: "N/A",
      order  : 3,
      sort   : true,
      source : {type: "provider"},
    },
    {
      name   : "appCategory",
      label  : "Application Category",
      type   : "string",
      default: "N/A",
      order  : 4,
      sort   : true,
      source : {type: "provider", transform: categoryName},
    },
    {
      name   : "accessKey",
      label  : "Access Key",
      type   : "string",
      default: "N/A",
      order  : 5,
      sort   : true,
      source : {type: "provider"},
    },
    {
      name   : "description",
      label  : "Description",
      type   : "string",
      default: "N/A",
      order  : 6,
      sort   : true,
      source : {type: "provider", transform: shortDesc},
    },
    {
      name   : "isActive",
      label  : "isActive",
      type   : "boolean",
      default: false,
      order  : 7,
      sort   : false,
      source : {type: "provider", transform: activeLabel, domComp: true},
    },
    {
      name   : "update",
      label  : "Update",
      type   : "string",
      default: "Update",
      order  : 8,
      sort   : false,
      source : {
        type   : "taskLink",
        task   : updateItem,
        params : ["item"],
        domComp: false
      },
      events : [{type: "click", action: updateItem, params: ["item"]}]
    },
    {
      name   : "delete",
      label  : "Delete",
      type   : "string",
      default: "Delete",
      order  : 10,
      sort   : false,
      source : {
        type   : "taskLink",
        task   : deleteItem,
        params : ["id"],
        domComp: false
      },
      events : [{type: "click", action: deleteItem, params: ["id"]}]
    },
  ]
  
</script>
  • usage example
  • Required and optional specifications
  • McDataTable: props (required and optional)
  • Required props: dataFields (Array) and dataItems (Array)
  • Optional props: dataTotal, paging, pageStart, pageLimits (Array), tableStyle, sortStyle
  • dataFields: => dataSpecs.ts
  • dataItems: => provider data records props : { dataFields: { type : Array, required: true, }, dataItems : { type : Array, required: true }, dataTotal : { type : Number, default: 0, }, paging : { type : Boolean, default: true, }, pageStart : { type : Number, default: 1, }, pageLimits: { type : Array, default: () => [10, 20, 30, 50, 100, 200], }, tableStyle: { type : Object, default: () => { return { table : "w3-table w3-striped w3-border w3-bordered w3-hoverable", tableHeader: "w3-red", tableBody : "w3-hover", } }, }, sortStyle : { type : Object, default: () => { return { asc : "fa fa-caret-up", desc: "fa fa-caret-down", } }, }, },