0.0.19 • Published 3 years ago

vue3-table-component v0.0.19

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

vue3-table-component

SampleCode

import VTable from '@makeupyourmind/vue3-table-component';

QuickStart

component

  <VTable
    v-model="selected"
    :is-loading="false"
    :use-api-sorting="false"
    :headers="headers"
    :items="desserts"
    :is-pagination-mode-enabled="false"
    :pagination-options="{
      totalPages: 1,
      perPage: 10,
    }"
    single-select
    show-select
    @handle-api-sorting="handleApiSorting"
    @row-click="rowClick"
  />

data

const selected = ref([]);

const headers = reactive([
  {
    text: 'Dessert (100g serving)', // Text that will be dipslayed in header
    // One of items shoud have key equals `name`. items = [{ name: 'Some name' }]
    // Then 'Some name' will be displayed in the header
    value: 'name',
    sortable: true, // Make column sortable
    resizable: true, // Make column resizable
    width: '350px', // Use custom width for column
  },
  {
    text: 'Calories',
    value: 'calories',
    sortable: true,
    resizable: true,
    width: '360px',
    defaultSort: 'asc|desc|ASC|DESC',
    fixed: true,
    style: {
      className: 'calories-class' | ['calories-class', 'one-more-class'],
      expectedValue: 250,
      condition: '>',
    },
  },
  {
    text: 'Fat (g)',
    value: 'fat',
  },
  {
    text: 'Carbs (g)',
    value: 'carbs',
  },
]);

const desserts = reactive([
  {
    name: 'Frozen Yogurt',
    calories: 159,
    fat: 6.0,
    carbs: 24,
  },
  {
    name: 'Ice cream sandwich',
    calories: 237,
    fat: 9.0,
    carbs: 37,
  },
  {
    name: 'Cupcake',
    calories: 305,
    fat: 3.7,
    carbs: 67,
  },
  {
    name: 'Lollipop',
    calories: 392,
    fat: 0.2,
    carbs: 98,
  },
]);

Component Props

Prop nameRequiredDefault valueDescription
headersYesN/AItems that will be displayed in table header
itemsYesN/AContent of table
isLoadingNofalseProp to indicate that data in the table is currently loading
loaderMessageNonullCustomize default loader message
useApiSortingNofalseIf true then do sort using API, but not using table. Need @handle-api-sorting event
paginationOptionsNofalseOptions that will be used when use default pagination
isPaginationModeEnabledNo{ totalPages: 1, perPage: 10 }Display slot with pagination. By default uses package basic pagination
show-selectNofalseAllow to select row
select-widthNonullManage width for selectable block. Can be in px, rem. By default uses 70px value. That value is minimum that allowed to be used.
select-fixedNofalseMake selectable field fixed to the left side
single-selectYesfalseHide/Show select all items checkbox
v-model="modelName"NonullTo store the selected values

Header props

Prop nameRequiredDefault valueDescription
textYesN/AText that uses in the header
valueYesN/AContains the key by that should be in item object to get ceil content
sortableNofalseSortable field
resizableNofalseResizable field
widthNonullUse custom width for column
fixedNonullMake a column fixed to the left side
defaultSortNonullDefault sorting for specific field. Example asc, ASC, desc, DESC
styleNonullApply custom class by some condition

Slots

pagination

Support slot that uses to display component pagination. By default, uses own pagination

<VTable :is-pagination-mode-enabled="true">
    <template #pagination>
    <!-- Your custom pagination goes here  -->
    </template>
</VTable>

loader

Overwrite default loader

<VTable :is-loading="true">
    <template #loader>
    <!-- Your custom loader goes here  -->
    </template>
</VTable>

Events

@handle-api-sorting - event fires when we want to use API sorting (:use-api-sorting="true"),

Send to API sortable fields in array format like [{field: 'name', order: 'asc'}]

<VTable
  ...restProps
  @handle-api-sorting="handleApiSorting"
>
</VTable>
export default {
    setup() {
        const handleApiSorting = (sortableFields) => {
          console.log('handleApiSorting', sortableFields);
          // some API request goes here where we paste these sortableFields
        };
    
        return {
          handleApiSorting
        }
    }
}

@row-click - Handle row click. As param would be the clicked item.

<VTable
  ...restProps
  @row-click="rowClick"
>
</VTable>
export default {
    setup() {
        const rowClick = (clickedItem) => {
          console.log('row click', clickedItem);
        };

        return {
          rowClick
        }
    }
}
0.0.19

3 years ago

0.0.18

3 years ago

0.0.17

3 years ago

0.0.16

3 years ago

0.0.15

3 years ago

0.0.1

3 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.14

4 years ago

0.0.13

4 years ago

0.0.12

4 years ago

0.0.11

4 years ago

0.0.10

4 years ago