Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

devextreme-vue

Package Overview
Dependencies
Maintainers
13
Versions
596
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

devextreme-vue

DevExtreme Vue UI and Visualization Components

  • 18.2.10-pre-19170
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
15K
increased by0.22%
Maintainers
13
Weekly downloads
 
Created
Source

DevExtreme Vue UI and Visualization Components

Build Status NPM

This project allows you to use DevExtreme Vue Components.

Getting Started

You can try this live example, feature-based examples or configure local development environment as described below.

Prerequisites

Node.js and npm are required

Install DevExtreme

Install the devextreme and devextreme-vue npm packages:

npm install --save devextreme devextreme-vue
Additional Configuration

The further configuration steps depend on which build tool, bundler or module loader you are using:

Import Stylesheets

Import dx.common.css and a predefined theme stylesheet in the application's main file:

import 'devextreme/dist/css/dx.common.css';
import 'devextreme/dist/css/dx.light.compact.css';

Import DevExtreme Components

Import the DevExtreme components you are going to use in a single file component...

<template>
    <dx-button :text='text'/>
</template>

<script>
import DxButton from 'devextreme-vue/button';

import 'devextreme/dist/css/dx.common.css';
import 'devextreme/dist/css/dx.light.compact.css';

export default {
  name: 'HelloWorld',
  data() {
    return {
      text: 'Hello!'
    };
  },
  components: {
    DxButton
  }
};
</script>

... or in a jsx render function...

import Vue from 'vue';
import { DxButton } from 'devextreme-vue';

import 'devextreme/dist/css/dx.common.css';
import 'devextreme/dist/css/dx.light.compact.css';

new Vue({
  el: '#app',
  data: function() {
    return {
      text: "Hello!"
    }
  },
  render: function(h) {
    return (
      <DxButton text={this.text} />
    )
  }
});

... or directly in a vue template.

import Vue from 'vue';
import DxButton from 'devextreme-vue/button';

import 'devextreme/dist/css/dx.common.css';
import 'devextreme/dist/css/dx.light.compact.css';

new Vue({
  el: '#app',
  components: { DxButton },
  template: '<dx-button :text="text" />',
  data() {
    return {
      text: 'Hello!'
    };
  }
});

API Reference

The complete list of components and their APIs are described in the DevExtreme API Reference.

Component Configuration

Set Component Option

  • A constant string value (for example, the Button text):
<dx-button text="Simple button" />
  • A constant non-string value (for example, the CheckBox value):
<dx-check-box :value="true" />
  • A value from a component data:
<dx-button :text="text" />

where : is a shorthand for v-bind directive.

Two-way Binding

Use the sync modifier to bind a bindingProperty to a widget option:

<dx-text-box :value.sync="bindingProperty" />

Editors Value Binding

The DevExtreme Vue editors also support v-model directive that creates two-way binding on the editor's value (for example, TextBox value):

<dx-text-box v-model="text" />

Custom Templates

You can customize widget elements' appearance via the corresponding template properties.

To specify a DevExtreme Vue Component template's markup, use a named slot. You should also specify a slot scope to access the template element's data.

For instance, you can specify the itemTemplate:

<div id="app">
    <dx-list :items="items">
        <div slot="item" slot-scope="data">
            <i>This is my template for {{data}}</i>
        </div>
    </dx-list>
</div>
import Vue from 'vue';
import DxList from 'devextreme-vue/list';

new Vue({
  el: '#app',
  components: { DxList },
  data() {
    return {
      items: [1, 2, 3, 4]
    };
  }
});

item is the default name of the dxList widget's item template. You can specify a custom name for the template and for your slot:

<div id="app">
    <dx-list :items="items" item-template="my-template">
        <div slot="my-template" slot-scope="data">
            <i>This is my template for {{data}}</i>
        </div>
    </dx-list>
</div>

Components with Transcluded Content

The following widgets support putting a content directly to the widget's container:

For example, you can specify the ScrollView widget's content as follows:

<dx-scroll-view>
    <div>Some scrollable content</div>
</dx-scroll-view>

Event Handling

You can subscribe to DevExtreme Component events using the Vue's v-on directive (or @ shorthand)

<dx-text-box v-model="text" @focusIn="handleFocusIn" />
data: function() {
  return {
    text: "text",
    handleFocusIn: () => {
      this.text = 'focused!';
    }
  };
}

You can find the full list of component events in each DevExtreme widget API Reference's Events section (for example, TextBox events).

Getting a Widget Instance

A widget instance is required to call methods. Pass a component key to the $refs property property to get a component whose instance field stores the widget instance. The component's key is defined in the component's ref attribute.

<template>
    <div title="Accessing Widget Instance">
        <dx-text-box :ref="textBoxRefName"/>
        <br/>
        <dx-button text="Set focus" @click="setFocus"/>
    </div>
</template>

<script>
import { DxButton, DxTextBox } from "devextreme-vue";

const textBoxRefName = "some-ref-name";

export default {
  data: function() {
    return {
      textBoxRefName
    };
  },

  components: {
    DxTextBox,
    DxButton
  },

  methods: {
    setFocus: function() {
      this.textBox.focus();
    }
  },

  computed: {
    textBox: function() {
      return this.$refs[textBoxRefName].instance;
    }
  }
};
</script>

Type Checks and TypeScript Support

You should specify proper values for the components' properties because DevExtreme Vue components use Prop Validation and Type Checks. Otherwise, Vue produces a console warning (if you are using the development build).

We also provide TypeScript declarations for DevExtreme Components. Strict typing allows you to catch many bugs and improve your workflow by adding features like auto-completion and automated refactoring.

This example demonstrates how to use DevExtreme Vue components with TypeScript.

DevExtreme Data Layer and Utils

The DevExtreme includes a Data Layer and Utils that can be helpful in different scenarios.

DevExtreme Validation

DevExtreme Vue editors support built-in data validation.

<dx-validation-group>
  <dx-text-box value="email@mail.com">
    <dx-validator :validationRules="validationRules.email" />
  </dx-text-box>
  <dx-text-box value="password">
    <dx-validator :validationRules="validationRules.password" />
  </dx-text-box>
  <dx-validation-summary />
  <dx-button text="Submit" @click="validate"/>
</dx-validation-group>
import { DxButton, DxTextBox, DxValidator, DxValidationGroup, DxValidationSummary } from "devextreme-vue";

export default {
  components: {
    DxButton,
    DxTextBox, 
    DxValidator,
    DxValidationGroup,
    DxValidationSummary
  },
  methods: {
    validate(params) {
      const result = params.validationGroup.validate();
      if (result.isValid) {
          // form data is valid
          //params.validationGroup.reset();
      }
    }
  },
  data: function() {
    return {
      validationRules: {
        email: [
            { type: "required", message: "Email is required." },
            { type: "email", message: "Email is invalid." }
        ],
        password: [
            { type: "required", message: "Password is required." }
        ]
    }};
  }
};

Configuration Components

DevExtreme Vue Components provide configuration components for the underlying widget's complex nested options.

Use a named import to get a configuration component.

import DxChart, { DxTooltip } from "devextreme-vue/chart"; 

You can use all data-bind features (such as .sync modifier) in your nested configuration components.

Basic Usage

The following example demonstrates how to configure the dxChart widget's tooltip option:

<dx-chart
  :data-source="dataSource"
  title="Pizza Shop Complaints">
  <dx-tooltip :enabled="showTooltip"/>
</dx-chart>

<dx-button text="Toggle tooltip" @click="toggleTooltip"/>
import DxChart, { DxTooltip } from "devextreme-vue/chart"; 
import DxButton from "devextreme-vue/button"; 

import { complaintsData } from './data.js';

export default {
  components: {
    DxChart,
    DxTooltip,
    DxButton
  },
  data() {
    return {
      dataSource: complaintsData,
      showTooltip: false
    };
  },
  methods: {
    toggleTooltip() {
      this.showTooltip = !this.showTooltip;
    }
  }
};

Collection Options

You can also use configuration components for complex collection options. The following example demonstrates how to configure the dxDataGrid widget's columns option:

<dx-data-grid :data-source="dataSource">
  <dx-column data-field="firstName"/>
  <dx-column data-field="lastName" caption="Last Name" :visible.sync="showLastName"/>
</dx-data-grid>

<dx-check-box text="Show the 'Last Name' column" v-model="showLastName"/>
import DxDataGrid, { DxColumn } from "devextreme-vue/data-grid"; 
import DxCheckBox from "devextreme-vue/check-box"; 

import { data } from './data.js';

export default {
  components: {
    DxDataGrid,
    DxColumn,
    DxCheckBox
  },
  data() {
    return {
      dataSource: data,
      showLastName: true
    };
  }
};

Note that configuration components are not provided for options that accept a type that depends on another option's value. For example, the DataGrid's editorOptions, Form's editorOptions, Toolbar's widget options.

If a configuration component has the template option, you can put the default-scoped content directly into this component. The following example demonstrates how to specify a template for a dx-item component:

<dx-list>
  <dx-item>
    <span slot-scope="_">orange</span>
  </dx-item>
  <dx-item>
    <span slot-scope="_">white</span>
  </dx-item>
  <dx-item>
    <span slot-scope="_">black</span>
  </dx-item>
</dx-list>
import {
  DxList,
  DxItem
} from "devextreme-vue/list";

export default {
  components: {
    DxList,
    DxItem
  }
};

License

DevExtreme Vue components are released as an MIT-licensed (free and open-source) DevExtreme add-on.

See the DevExtreme License for more information.

A free trial is available

Support & Feedback

Keywords

FAQs

Package last updated on 19 Jun 2019

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc