Array Table

It allows multiple data entries as arrays in tabular format. Supports adding new data, deleting and updating data.

Form

<template>
  <v-row no-gutters>
    <v-col lg="8" md="12" sm="12">
      <va-array-table-input source="employeeChildren" :title="$t('resources.employees.fields.employeeChildren')" primary-key="childId" :headers="headers" :fields="fields" :generate-uid="true">
       <template v-slot: field>
         <va-text-input :key="field.source" v-model="employeeChildrenForm.childName" variant="outlined" :error-messages="childNameErrors" clearable>
         </va-text-input>
       </template>
       <template v-slot: field>
         <va-date-input :key="field.source" v-model="employeeChildrenForm.childBirthdate" variant="outlined" :error-messages="childBirthdateErrors">
         </va-date-input>
       </template>
      </va-array-table-input>
    </v-col>
  </v-row>
</template>
<script>
import { useVuelidate } from "@vuelidate/core";
import { required, maxLength, numeric } from "@vuelidate/validators";
import Utils from "vuetify-admin/src/mixins/utils";
import Resource from "vuetify-admin/src/mixins/resource";
import { provide } from 'vue'

export default {
  props: ["id", "item"],
  mixins: [Utils, Resource],
  setup() {
    let vuelidate = useVuelidate();
    provide('v$', vuelidate)
    return { v$: vuelidate }
  },
  data() {
    return {
      model: {
        id: null,
        employeeChildren: null,
      },
      employeeChildrenHeaders: [
        { key: "childName", width: "40%" },
        { key: "childBirthdate", width: "40%" },
        { key: "actions" },
      ],
      employeeChildrenFields: [
        {
          source: "childName",
          type: "text",
        },
        {
          source: "childBirthdate",
          type: "date",
        },
      ]
    };
  },
  validations() {
    return {
      // model: {},
      employeeChildrenForm: {
        childName: {
          required,
        },
        childBirthdate: {
          required,
        }
      }
    }
  },
  created() {
    this.model.id = this.generateId(this);
  },
  computed: {
    employeeChildrenForm: {
      get() {
        return this.$store.getters[`${this.resource}/getRow`];
      },
      set(val) {
        this.$store.commit(`${this.resource}/setRow`, val);
      } 
    },
    childNameErrors() {
      const errors = [];
      const field = "childName";
      if (!this.v$["employeeChildrenForm"][field].$dirty) return errors;
      this.v$["employeeChildrenForm"][field].required.$invalid &&
        errors.push(this.$t("v.text.required"));
      return errors;
    },
    childBirthdateErrors() {
      const errors = [];
      const field = "childBirthdate";
      if (!this.v$["employeeChildrenForm"][field].$dirty) return errors;
      this.v$["employeeChildrenForm"][field].required.$invalid &&
        errors.push(this.$t("v.text.required"));
      return errors;
    },
  },
}
</script>

Mixins

  • Input
  • InputWrapper
  • Source
  • Resource

Properties

Property Type Description
class String The array table assigns a value to the html class attribute of the div element surrounding it.
source string The property of the resource to fetch the value to display. Supports dot display for slot used object.
model string By default source will be the last name sent to the API service for create/update. This support allows you to override this default behavior.
title string Sets the header of the array table.
headers array Determines the column headers of the array table.
fields array Places the va-entries to use from the array table.
primaryKey string Sets the key field name for the Array. This name is required for backend side validation and database registration.
errorMessages array Allows display of assigned form validation errors.

Slots

Name Description
top Edits the section of the series title when needed.
bottom Arranges the bottom section of the array table.
headers Customizes the columns of the array table.
item.actions Customizes the operations section of the array table.

Events

After the form saving stage of the Array Table events, it receives the responses returned from the server and organizes the actions accordingly.

Event Name Description
save It allows you to access the object of the saved data after the form row is saved.
delete It allows you to access the object of the deleted data after the form row is deleted.
edit It allows you to store the object belonging to the data edited while the form row is open.