JavaScript/jQuery CardView - Getting Started

DevExtreme includes multiple data management components. You can use them to display tabular, hierarchical, multidimensional data, or present information as cards. For more information about these components and their features, see How to Choose a Data Management Component.

NOTE
Before you start the tutorial, ensure DevExtreme is installed in your application.

CardView is a UI component that displays data in a card-based format. You can use it for employee directories, contact lists, product catalogs, and task boards.

This tutorial explains how to add a CardView to a page and configure the component's core settings.

Each section in this tutorial covers a single configuration step. You can find the complete source code in the following GitHub repository:

View on GitHub

Create a CardView

Add DevExtreme to your jQuery application and use the following code to create a CardView:

index.js
index.html
  • $(function() {
  • $("#card-view").dxCardView({
  • // Configuration goes here
  • });
  • });
  • <html>
  • <head>
  • <!-- ... -->
  • <script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
  •  
  • <link rel="stylesheet" href="https://cdn3.devexpress.com/jslib/26.2.2beta/css/dx.light.css">
  • <link rel="stylesheet" href="index.css">
  •  
  • <script type="text/javascript" src="https://cdn3.devexpress.com/jslib/26.2.2beta/js/dx.all.js"></script>
  • <script type="text/javascript" src="index.js"></script>
  • </head>
  • <body class="dx-viewport">
  • <div id="card-view"></div>
  • </body>
  • </html>

Bind CardView to Data

The CardView component can load and update data from different data source types. To use a local array, assign it to the dataSource property and specify the key field in the keyExpr property:

index.js
data.js
  • $(function() {
  • $("#card-view").dxCardView({
  • dataSource: employees,
  • keyExpr: "ID",
  • });
  • });
  • const employees = [
  • {
  • ID: 1,
  • FullName: "John Heart",
  • Position: "CEO",
  • Picture: "images/employees/01.png",
  • Department: "Management",
  • Phone: "+1 (213) 555-9392",
  • Email: "jheart@dx-email.com"
  • },
  • {
  • ID: 2,
  • FullName: "Samantha Bright",
  • Position: "COO",
  • Picture: "images/employees/30.png",
  • Department: "Management",
  • Phone: "+1 (213) 555-2858",
  • Email: "samanthab@dx-email.com"
  • },
  • {
  • ID: 3,
  • FullName: "Arthur Miller",
  • Position: "CTO",
  • Picture: "images/employees/10.png",
  • Department: "Management",
  • Phone: "+1 (310) 555-8583",
  • Email: "arthurm@dx-email.com"
  • },
  • {
  • ID: 4,
  • FullName: "Robert Reagan",
  • Position: "CMO",
  • Picture: "images/employees/03.png",
  • Department: "Management",
  • Phone: "+1 (818) 555-2387",
  • Email: "robertr@dx-email.com"
  • },
  • {
  • ID: 5,
  • FullName: "Greta Sims",
  • Position: "HR Manager",
  • Picture: "images/employees/04.png",
  • Department: "Human Resources",
  • Phone: "+1 (818) 555-6546",
  • Email: "gretas@dx-email.com"
  • },
  • {
  • ID: 6,
  • FullName: "Brett Wade",
  • Position: "IT Manager",
  • Picture: "images/employees/05.png",
  • Department: "IT",
  • Phone: "+1 (626) 555-0358",
  • Email: "brettw@dx-email.com"
  • },
  • ];

Configure Columns (Fields)

CardView uses the concept of columns from DataGrid. While it has rows and columns, the columns appear as fields on each card. The header shows the column names, and each field on a card includes a caption that usually matches the column dataField, and a unique value specific to the card.

The following code snippet restricts the CardView columns (fields) to FullName, Position, and Email and allows column reordering:

index.js
  • $(function() {
  • $("#card-view").dxCardView({
  • // ...
  • allowColumnReordering: true,
  • columns: [
  • {
  • dataField: "FullName",
  • allowHiding: false
  • },
  • "Position",
  • "Email"
  • ],
  • });
  • });

Filter and Search Data

The CardView includes the following UI elements used to search and filter data:

In this tutorial, the header filter and the search panel are displayed:

index.js
  • $(function() {
  • $("#card-view").dxCardView({
  • // ...
  • headerFilter: {
  • visible: true
  • },
  • searchPanel: {
  • visible: true
  • },
  • });
  • });

Select Cards

CardView supports single and multiple selection modes. Use the selection.mode property to specify the mode.

index.js
  • $(function() {
  • $("#card-view").dxCardView({
  • // ...
  • selection: {
  • mode: "multiple"
  • },
  • });
  • });

Add Pagination

To add pagination to CardView, configure the following settings:

  • paging - enables paging
  • pager - activates UI elements for pagination
index.js
  • $(function() {
  • $("#card-view").dxCardView({
  • // ...
  • paging: {
  • pageSize: 3,
  • },
  • pager: {
  • showInfo: true,
  • showNavigationButtons: true,
  • showPageSizeSelector: true
  • },
  • });
  • });

Configure Column Chooser

CardView displays all columns from the columns array. To hide a column, set its visible property to false. Hidden columns appear in the columnChooser. Users can restore hidden columns from it. To enable the column chooser, set the columnChooser.enabled property to true. If a column should not be visible in the column chooser, do not declare it in the columns array.

You can also specify other column chooser settings, such as mode, position, and selection:

index.js
  • $(function() {
  • $("#card-view").dxCardView({
  • // ...
  • columnChooser: {
  • enabled: true,
  • height: 340,
  • mode: "select",
  • position: {
  • my: "right top",
  • at: "right bottom",
  • of: ".dx-cardview-column-chooser-button"
  • },
  • selection: {
  • selectByClick: true
  • }
  • }
  • });
  • });