DevExtreme Vue - Best Practices

Using Unions Instead of Base Classes

Inheritance is a part of internal implementation. You should not rely on the knowledge of relationships between base classes and their descendants. For generalization, use a union to define your own type.

For example, if you need a type for properties of multiple editor components, define the following union:

App.vue
  • type EditorProps = DxTextAreaTypes.Properties | DxTextBoxTypes.Properties | DxAutocompleteTypes.Properties | DxLookupTypes.Properties;

Generic Parameters

Some types are generic. This is mostly the case for data-aware component types, such as DataGrid:

App.vue
  • <template>
  • <div>
  • <DxButton
  • text="Disable DataGrid"
  • @click="onButtonClick"
  • />
  • <DxDataGrid
  • :data-source="dataSource"
  • ref="dataGridRef"
  • @editor-preparing="onEditorPreparing"
  • >
  • </DxDataGrid>
  • </div>
  • </template>
  • <script setup lang="ts">
  • import { ref } from "vue";
  •  
  • import { DxDataGrid } from "devextreme-vue/data-grid";
  • import { DxButton } from "devextreme-vue/button";
  •  
  • import { type DxDataGridTypes } from "devextreme-vue/data-grid";
  • import type dxDataGrid from 'devextreme/ui/data_grid';
  • import { type Employee } from '../data';
  •  
  • const dataGridRef = ref<DxDataGrid>();
  •  
  • function onButtonClick() {
  • const dataGridInstance: dxDataGrid<Employee, number> = dataGridRef.value?.instance!;
  • dataGridInstance.option("disabled", true);
  • }
  •  
  • function onEditorPreparing(e: DxDataGridTypes.EditorPreparingEvent<Employee, number>) {
  • if (e.dataField === 'LastName' && e.parentType === 'dataRow') {
  • e.editorOptions.disabled = e.row?.data?.FirstName === '';
  • }
  • }
  • </script>