Angular CardView - columns
An array of CardView columns.
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.
alignment
Aligns the content of the entire column.
The default alignment for all types of content is 'left'.
allowEditing
Specifies whether a user can edit cards in this column at runtime. Inherits the value of the editing.allowUpdating property.
allowHeaderFiltering
Specifies whether data of this column can be filtered in header filter. Inherits the value of the allowFiltering property.
allowHiding
Specifies whether a user can hide the column using the column chooser at runtime. Applies only if columnChooser.enabled is true
.
allowReordering
Specifies whether users can reorder this column. Overrides the allowColumnReordering property value.
allowSearch
Specifies whether this column can be searched. Applies only if searchPanel.visible is true
. Inherits the value of the allowFiltering property.
allowSorting
Specifies whether a user can sort rows by this column at runtime. Applies only if sorting.mode differs from "none".
calculateDisplayValue
Calculates custom display values for column fields. Requires specifying the dataField or calculateFieldValue property.
The data of the card to which the field belongs.
The this
keyword refers to the column's configuration.
The value for the field to display.
This property accepts the name of the data source field that supplies display values or a function that combines display values. Specify this function only if all data processing operations are executed on the client.
jQuery
$(function() { $("#cardViewContainer").dxCardView({ columns: [{ dataField: "countryID", // supplies values for editing calculateDisplayValue: function (rowData) { // combines display values return rowData.capital + " (" + rowData.country + ")"; } }] }); });
Angular
<dx-card-view ... > <dxi-card-view-column dataField="countryID" <!-- supplies values for editing --> [calculateDisplayValue]="getCountryWithCapital"> <!-- combines display values --> </dxi-card-view-column> </dx-card-view>
import { DxCardViewModule } from "devextreme-angular"; // ... export class AppComponent { getCountryWithCapital(rowData) { return rowData.capital + " (" + rowData.country + ")"; } } @NgModule({ imports: [ // ... DxCardViewModule ], // ... })
Vue
<template> <DxCardView> <DxColumn data-field="countryID" <!-- supplies values for editing --> :calculate-display-value="getCountryWithCapital" <!-- combines display values --> /> </DxCardView> </template> <script> import 'devextreme/dist/css/dx.light.css'; import DxCardView, { DxColumn } from 'devextreme-vue/card-view'; export default { components: { DxCardView, DxColumn }, methods: { getCountryWithCapital(rowData) { return rowData.capital + " (" + rowData.country + ")"; } } } </script>
React
import React from 'react'; import 'devextreme/dist/css/dx.light.css'; import CardView, { Column } from 'devextreme-react/card-view'; class App extends React.Component { // ... render() { return ( <CardView> <Column dataField="countryID" <!-- supplies values for editing --> calculateDisplayValue={this.getCountryWithCapital} <!-- combines display values --> /> </CardView> ); } getCountryWithCapital(rowData) { return rowData.capital + " (" + rowData.country + ")"; } } export default App;
The UI component utilizes the specified display values in sorting and searching.
Do not use this property to format text in cells. Instead, use the format, customizeText, or fieldTemplate property.
calculateFieldValue
Calculates custom field values.
The data of the card to which the field belongs.
The this
keyword refers to the column's configuration.
A field's custom value.
jQuery
$(#dxCardView).dxCardView({ // ... columns: [{ caption: 'Location', calculateFieldValue(cardData) { return `${cardData.City}, ${cardData.State}`; } }] })
Angular
<dx-card-view ... > <dxi-card-view-column caption="Location" [calculateFieldValue]="calculateLocation" ></dxi-card-view-column> </dx-card-view>
// ... export class AppComponent { calculateLocation(cardData: Employee): string { return `${cardData.City}, ${cardData.State}`; } }
Vue
<template> <DxCardView ... > <DxColumn caption="Location" :calculate-field-value="calculateLocation" /> </DxCardView> </template> <script setup lang="ts"> import DxCardView, { DxColumn } from 'devextreme-vue/card-view'; function calculateLocation(cardData: Employee): string { return `${cardData.City}, ${cardData.State}`; } </script>
React
import CardView, { Column } from 'devextreme-react/card-view'; function calculateLocation(cardData: Employee): string { return `${cardData.City}, ${cardData.State}`; } function App() { return ( <CardView ... > <Column caption="Location" calculateFieldValue={calculateLocation} /> </CardView> ) }
calculateFilterExpression
Specifies the column's custom rules to filter data.
A user input value.
Contains an array if the selectedFilterOperation
is one of the following: "between", "anyof", "noneof".
A selected filter operation.
A UI element used to filter data.
Possible values: "headerFilter", "filterBuilder", "search".
The this
keyword refers to the column's configuration.
jQuery
$(#dxCardView).dxCardView({ // ... columns: [{ dataField: 'OrderDate', calculateFilterExpression(value, selectedFilterOperations, target) { if (value === 'weekends') { return [[getOrderDay, '=', 0], 'or', [getOrderDay, '=', 6]]; } return this.defaultCalculateFilterExpression(value, selectedFilterOperations, target); }, }] }) function getOrderDay(rowData) { return (new Date(rowData.OrderDate)).getDay(); }
Angular
<dx-card-view ... > <dxi-card-view-column dataField="OrderDate" [calculateFilterExpression]="calculateOrderDateFilterExpression" ></dxi-card-view-column> </dx-card-view>
function getOrderDay(rowData: orderObj) { return new Date(rowData.OrderDate).getDay(); } // ... export class AppComponent { calculateOrderDateFilterExpression(this: DxCardViewTypes.Column, value, selectedFilterOperations, target) { if (value === 'weekends') { return [[getOrderDay, '=', 0], 'or', [getOrderDay, '=', 6]]; } return this.defaultCalculateFilterExpression(value, selectedFilterOperations, target); } }
Vue
<template> <DxCardView ... > <DxColumn data-field="OrderDate" :calculate-filter-expression="calculateOrderDateFilterExpression" /> </DxCardView> </template> <script setup lang="ts"> import DxCardView, { DxColumn, type DxCardViewTypes } from 'devextreme-vue/card-view'; function getOrderDay(rowData: orderObj) { return new Date(rowData.OrderDate).getDay(); } function calculateOrderDateFilterExpression(this: DxCardViewTypes.Column, value, selectedFilterOperations, target) { if (value === 'weekends') { return [[getOrderDay, '=', 0], 'or', [getOrderDay, '=', 6]]; } return this.defaultCalculateFilterExpression(value, selectedFilterOperations, target) as any; } </script>
React
import CardView, { Column } from 'devextreme-react/card-view'; function getOrderDay(rowData: orderObj) { return new Date(rowData.OrderDate).getDay(); } function calculateOrderDateFilterExpression(value, selectedFilterOperations, target) { if (value === 'weekends') { return [[getOrderDay, '=', 0], 'or', [getOrderDay, '=', 6]]; } return this.defaultCalculateFilterExpression(value, selectedFilterOperations, target); } function App() { return ( <CardView ... > <Column dataField="OrderDate" calculateFilterExpression={calculateOrderDateFilterExpression} /> </CardView> ) }
calculateSortValue
Calculates custom values used to sort this column.
The data of the card to which the field belongs.
The this
keyword refers to the column's configuration.
The value to be used in sorting.
This property requires the name of the data source field used for sorting this column or a function to obtain those values. The following code snippet demonstrates the first approach:
jQuery
$(function() { $("#cardViewContainer").dxCardView({ columns: [{ dataField: "Position", // supplies column values calculateSortValue: "isOnVacation" // supplies values used to sort the Position column }] }); });
Angular
<dx-card-view ... > <dxi-card-view-column dataField="Position" <!-- supplies column values --> calculateSortValue="isOnVacation"> <!-- supplies values used to sort the Position column --> </dxi-card-view-column> </dx-card-view>
Vue
<template> <DxDataGrid ... > <DxColumn data-field="Position" <!-- supplies column values --> calculate-sort-value="isOnVacation" <!-- supplies values used to sort the Position column --> /> </DxDataGrid> </template> <script setup lang="ts"> import { DxDataGrid, DxColumn } from 'devextreme-vue/data-grid'; </script>
React
import React from 'react'; import DataGrid, { Column } from 'devextreme-react/data-grid'; function App() { // ... return ( <DataGrid ...> <Column dataField="Position" // supplies column values calculateSortValue="isOnVacation" // supplies values used to sort the Position column /> </DataGrid> ); } export default App;
The following code snippet uses calculateSortValue to concatenate State and City values for sorting the Employee column:
jQuery
$(function() { const cardView = $("#cardViewContainer").dxCardView({ columns: [{ dataField: "Employee", sortOrder: "asc", calculateSortValue: function (cardData) { return cardData.State + cardData.City; } }] }).dxCardView("instance"); });
Angular
<dx-card-view ... > <dxi-card-view-column dataField="Employee" sortOrder="asc" [calculateSortValue]="sortByLocation"> </dxi-card-view-column> </dx-card-view>
import { DxCardViewModule } from "devextreme-angular"; // ... export class AppComponent { sortByLocation (cardData) { return cardData.State + cardData.City; } }
Vue
<template> <DxDataGrid ... > <DxColumn data-field="Employee" :calculate-sort-value="sortByLocation" /> </DxDataGrid> </template> <script setup lang="ts"> import { DxDataGrid, DxColumn } from 'devextreme-vue/data-grid'; const sortByLocation = (cardData) => { return cardData.State + cardData.City; } </script>
React
import React from 'react'; import DataGrid, { Column } from 'devextreme-react/data-grid'; function sortByLocation(cardData){ return cardData.State + cardData.City; } function App() { // ... return ( <DataGrid ...> <Column dataField="Employee" calculateSortValue={sortByLocation} /> </DataGrid> ); } export default App;
caption
Specifies a caption for the column.
Use this property to display a descriptive or friendly name for the column. If this property is not set, the caption will be generated from the name of the dataField.
customizeText
Customizes text displayed in field values.
Information on the current field.
Name | Type | Description |
---|---|---|
groupInterval | | |
Indicates how header filter values were combined into groups. Available if target is "headerFilter". |
target |
The UI element where the customizeText function was called: "card", "headerFilter", "search", "filterPanel", or "filterBuilder". |
|
value | any |
The field value. |
valueText |
The formatted value converted to a string. |
The this
keyword refers to the column's configuration.
The text the field value should display.
jQuery
$(function() { $("#cardViewContainer").dxCardView({ // ... columns: [{ dataField: "Temperature", customizeText: function(fieldInfo) { return fieldInfo.value + " °C"; } }] }); });
Angular
<dx-card-view ... > <dxi-card-view-column dataField="Temperature" [customizeText]="customizeText" ></dxi-card-view-column> </dx-card-view>
import { Component } from '@angular/core'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { customizeText(fieldInfo) { return fieldInfo.value + " °C"; } }
Vue
<template> <DxCardView ... > <DxColumn data-field="Temperature" :customize-text="customizeText" /> </DxCardView> </template> <script setup lang="ts"> import 'devextreme/dist/css/dx.light.css'; import { DxCardView, DxColumn } from "devextreme-vue/card-view"; function customizeText(fieldInfo) { return fieldInfo.value + " °C"; } </script>
React
import React from 'react'; import 'devextreme/dist/css/dx.light.css'; import CardView, { Column } from "devextreme-react/card-view"; const customizeText = (fieldInfo) => { return fieldInfo.value + " °C"; } function App() { return ( <CardView ... > <Column dataField="Temperature" customizeText={customizeText} /> </CardView> ); } export default App;
dataField
Binds the column to a field of the dataSource.
Review the following notes about data binding:
If you create an unbound column (use the calculateFieldValue function), specify the columns[].name property instead of dataField.
Data field names cannot be equal to
this
and should not contain the following characters:.
,:
,[
, and]
.Column caption is generated from the dataField value. If you want to use a custom caption, specify it in the caption property. Unlike dataField, caption can contain any characters.
dataType
Converts column values to a different data type.
If data fields have values of one type but need to be another in the UI component, set the correct type in this property.
falseText
In a boolean column, replaces all false items with a specified text.
See Also
- columns[].trueText
fieldCaptionTemplate
Specifies a custom template for the field caption.
jQuery
$(#dxCardView).dxCardView({ // ... columns: [{ // ... fieldCaptionTemplate(data) { return $('<div>') .append( $('<i>').addClass("dx-icon-errorcircle"), $('<span>').text(data.field.column.caption) ) }, }] })
Angular
<dx-card-view ... > <dxi-card-view-column ... fieldCaptionTemplate="captionTemplate" ></dxi-card-view-column> <div *dxTemplate="let data of 'captionTemplate'"> <i class="dx-icon-errorcircle"></i> <span>{{ data.field.column.caption }}</span> </div> </dx-card-view>
Vue
<template> <DxCardView ... > <DxColumn ... field-caption-template="captionTemplate" /> <template #captionTemplate="{ data }"> <div> <i class="dx-icon-errorcircle"></i> <span>{{ data.field.column.caption }}</span> </div> </template> </DxCardView> </template>
React
import CardView, { CardViewTypes } from "devextreme-react/card-view" function captionRender(data: CardViewTypes.FieldTemplateData) { return ( <div> <i class="dx-icon-errorcircle"></i> <span>{data.field.column.caption}</span> </div> ) } // ... function App() { return ( <CardView ... > <Column ... fieldCaptionRender={captionRender} /> </CardView> ) }
fieldTemplate
Specifies a custom template for the field.
jQuery
$(#dxCardView).dxCardView({ // ... columns: [{ // ... fieldTemplate(data) { return $('<div>') .addClass('task__progress') .dxProgressBar({ value: data.field.value, }); } }] })
Angular
<dx-card-view ... > <dxi-card-view-column ... fieldTemplate="progressTemplate" ></dxi-card-view-column> <div *dxTemplate="let data of 'progressTemplate'"> <dx-progress-bar [value]="data.field.value" ></dx-progress-bar> </div> </dx-card-view>
Vue
<template> <DxCardView ... > <DxColumn ... field-template="progressTemplate" /> <template #progressTemplate="{ data }"> <DxProgressBar :value="data.field.value" /> </template> </DxCardView> </template> <script setup lang="ts"> import { DxCardView, DxColumn } from 'devextreme-vue/card-view'; import { DxProgressBar } from 'devextreme-vue/progress-bar'; // ... </script>
React
import CardView, { Column, CardViewTypes } from 'devextreme-react/card-view'; import { ProgressBar } from 'devextreme-react/progress-bar'; function progressRender(data: CardViewTypes.FieldTemplateData) { return ( <ProgressBar value={data.field.value} /> ) } // ... function App() { return ( <CardView ... > <Column ... fieldRender={progressRender} /> </CardView> ) }
fieldValueTemplate
Specifies a custom template for the field value.
jQuery
$(#dxCardView).dxCardView({ // ... columns: [{ dataField: 'Email', fieldValueTemplate(data) { return $('<a>') .attr('href', `mailto:${data.field.value}`) .text(data.field.text); } }] })
Angular
<dx-card-view ... > <dxi-card-view-column dataField="Email" fieldValueTemplate="emailTemplate" ></dxi-card-view-column> <div *dxTemplate="let params of 'emailTemplate'"> <a href="mailto:{{ params.field.value }}">{{ params.field.text }}</a> </div> </dx-card-view>
Vue
<template> <DxCardView ... > <DxColumn data-field="Email" field-value-template="emailTemplate" /> <template #emailTemplate="{ data }" > <a :href="`mailto:${data.field.value}`">{{ data.field.text }}</a> </template> </DxCardView> </template> <script setup lang="ts"> import DxCardView, { DxColumn } from 'devextreme-vue/card-view'; </script>
React
import CardView, { Column } from 'devextreme-react/card-view'; function EmailComponent(data) { return ( <a href={`mailto:${data.field.value}`}>{data.field.text}</a> ); } function App() { return ( <CardView ... > <Column dataField="Email" fieldValueComponent={EmailComponent} /> </CardView> ) }
filterType
Specifies whether a user changes the current filter by including (selecting) or excluding (clearing the selection of) values. Applies only if headerFilter.visible and allowHeaderFiltering are true
.
This property accepts the following values.
- include
Values in the header filter are unselected initially, and a user can select values to apply a filter. - exclude
All values in the header filter are selected initially. A user can deselect values to change the filter.
This property changes when the user clicks the Select all button in the header filter (only if header filter displays plain data):
Select all | filterType / filterValues |
---|---|
Button is not pressed | filterType: "include" filterValues: null |
Button is pressed | filterType: "exclude" filterValues: null |
filterValues
Specifies the values in the header filter.
Array<any>
format
Formats a value before it is displayed in a field.
See the format section for information on accepted values.
formItem
Configures the form item that the field produces in the editing state.
headerFilter
Specifies data settings for the header filter.
name
Specifies the column's unique identifier. If not set in code, this value is inherited from the dataField.
This property's value is used to refer to the column in code.
setFieldValue
Specifies a function to be invoked after the user has edited a field value, but before it is saved in the data source.
The this
keyword refers to the column's configuration.
This function allows you to process user input before it is saved to the data source. It accepts the newData, value, and currentCardData parameters. value is the user input that you should assign to one of the newData fields. Fill the empty newData object with fields whose values should be saved in the current row's data object. You can use the read-only currentCardData parameter to access the current card's data.
jQuery
$(function() { $("#cardViewContainer").dxCardView({ // ... columns: [ "Price", { dataField: "Count", dataType: "number", setFieldValue: function(newData, value, currentCardData) { newData.Count = value; newData.TotalPrice = currentCardData.Price * value; } }, "TotalPrice", // ... ] }); });
Angular
<dx-card-view ... > <dxi-card-view-column dataField="Price"></dxi-card-view-column> <dxi-card-view-column dataField="Count" dataType="number" [setFieldValue]="setFieldValue"> </dxi-card-view-column> <dxi--card-viewcolumn dataField="TotalPrice"></dxi-card-view-column> </dx-card-view>
import { Component } from '@angular/core'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { setFieldValue (newData, value, currentCardData) { newData.Count = value; newData.TotalPrice = currentCardData.Price * value; } }
Vue
<template> <DxCardView ... > <DxColumn data-field="Price" /> <DxColumn data-field="Count" data-type="number" :set-cell-value="setFieldValue" /> <DxColumn data-field="TotalPrice" /> </DxCardView> </template> <script setup lang="ts"> import 'devextreme/dist/css/dx.light.css'; import { DxCardView, DxColumn } from 'devextreme-vue/card-view'; const setFieldValue = (newData, value, currentCardData) => { newData.Count = value; newData.TotalPrice = currentCardData.Price * value; } </script>
React
import React from 'react'; import 'devextreme/dist/css/dx.light.css'; import { CardView, Column } from 'devextreme-react/card-view'; const App = () => { setFieldValue(newData, value, currentCardData) { newData.Count = value; newData.TotalPrice = currentCardData.Price * value; } render() { return ( <CardView ... > <Column dataField="Price" /> <Column dataField="Count" dataType="numeric" setFieldValue={setFieldValue}/> <Column dataField="TotalPrice" /> </CardView> ); } } export default App;
showInColumnChooser
Specifies whether the column chooser can contain the column header.
sortIndex
Specifies the index according to which columns participate in sorting.
This property accepts an integer specifying the index of the column in a collection of columns with applied sorting.
sortingMethod
Specifies a custom comparison function for sorting. Applies only when sorting is performed on the client.
A value to be compared.
A value to be compared.
The this
keyword refers to the column's configuration.
Specifies whether value1 goes before value2.
This function accepts two cell values and should return a number that indicates their sort order:
- Less than zero
value1 goes before value2. - Zero
value1 and value2 remain unchanged relative to each other. - Greater than zero
value1 goes after value2.
The function performs a culture-insensitive string comparison.
sortOrder
Specifies the sort order of column values.
Rows initially follow the order of the data source. To change the order, set the sortOrder property to "asc" for ascending or "desc" for descending. For multi-column sorting, set the sortIndex. Without this, sorted columns receive a sort index based on their placement in the columns array.
trueText
In a boolean column, replaces all true items with the specified text.
See Also
- columns[].falseText
validationRules
Specifies validation rules to be checked when field values are updated.
Array<RequiredRule | NumericRule | RangeRule | StringLengthRule | CustomRule | CompareRule | PatternRule | EmailRule | AsyncRule>
visibleIndex
Specifies the position of the column among other columns in the resulting UI component.
If you have technical questions, please create a support ticket in the DevExpress Support Center.