Pull down to refresh...
Release to refresh...
Refreshing...
-
Data Grid
- Overview
-
Data Binding
-
Paging and Scrolling
-
Editing
-
Grouping
-
Filtering and Sorting
- Focused Row
-
Row Drag & Drop
-
Selection
-
Columns
- State Persistence
-
Appearance
-
Templates
-
Data Summaries
-
Master-Detail
-
Export to PDF
-
Export to Excel
-
Adaptability
- Keyboard Navigation
-
Pivot Grid
- Overview
-
Data Binding
-
Field Chooser
-
Features
-
Export to Excel
-
Tree List
- Overview
-
Data Binding
- Sorting
- Paging
-
Editing
- Node Drag & Drop
- Focused Row
-
Selection
-
Filtering
-
Column Customization
- State Persistence
- Adaptability
- Keyboard Navigation
-
Scheduler
- Overview
-
Data Binding
-
Views
-
Features
- Virtual Scrolling
-
Grouping
-
Customization
- Adaptability
-
Html Editor
-
Chat
-
Diagram
- Overview
-
Data Binding
-
Featured Shapes
-
Custom Shapes
-
Document Capabilities
-
User Interaction
- UI Customization
- Adaptability
-
Charts
- Overview
-
Data Binding
-
Area Charts
-
Bar Charts
- Bullet Charts
-
Doughnut Charts
-
Financial Charts
-
Line Charts
-
Pie Charts
-
Point Charts
-
Polar and Radar Charts
-
Range Charts
-
Sparkline Charts
-
Tree Map
-
Funnel and Pyramid Charts
- Sankey Chart
-
Combinations
-
More Features
-
Export
-
Selection
-
Tooltips
-
Zooming
-
-
Gantt
- Overview
-
Data
-
UI Customization
- Strip Lines
- Export to PDF
- Sorting
-
Filtering
-
Gauges
- Overview
-
Data Binding
-
Bar Gauge
-
Circular Gauge
-
Linear Gauge
-
Navigation
- Overview
- Accordion
-
Menu
- Multi View
-
Drawer
-
Tab Panel
-
Tabs
-
Toolbar
- Pagination
-
Tree View
- Right-to-Left Support
-
Layout
-
Tile View
- Splitter
-
Gallery
- Scroll View
- Resizable
-
-
Editors
- Overview
- Autocomplete
-
Calendar
- Check Box
- Color Box
- Date Box
-
Date Range Box
-
Drop Down Box
-
Number Box
-
Select Box
- Switch
-
Tag Box
- Text Area
- Text Box
- Validation
- Custom Text Editor Buttons
- Right-to-Left Support
- Editor Appearance Variants
-
Forms and Multi-Purpose
- Overview
- Button Group
- Field Set
-
Filter Builder
-
Form
- Radio Group
-
Range Selector
- Numeric Scale (Lightweight)
- Numeric Scale
- Date-Time Scale (Lightweight)
- Date-Time Scale
- Logarithmic Scale
- Discrete scale
- Custom Formatting
- Use Range Selection for Calculation
- Use Range Selection for Filtering
- Image on Background
- Chart on Background
- Customized Chart on Background
- Chart on Background with Series Template
- Range Slider
- Slider
-
Sortable
-
File Management
-
File Manager
- Overview
-
File System Types
-
Customization
-
File Uploader
-
-
Actions and Lists
-
Maps
- Overview
-
Map
-
Vector Map
-
Dialogs and Notifications
-
Localization
Related Demos:
Your search did not match any results.
Loading...
Data Grid - Cell Customization
DataGrid allows you to modify cell style settings and custom paint cells in a PDF document.
Use the customizeCell function to customize the appearance settings of DataGrid cells in a PDF document. For example, you can change the text alignment and the background color of cells. The following function parameters are available:
- gridCell
Contains information about the source DataGrid cell. - pdfCell
Contains settings applied to a cell in a PDF document.
Was this demo helpful?
Feel free to share demo-related thoughts here.
If you have technical questions, please create a support ticket in the DevExpress Support Center.
Thank you for the feedback!
If you have technical questions, please create a support ticket in the DevExpress Support Center.
Backend API
x
@using DevExtreme.MVC.Demos.Models
@section ExternalDependencies {
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
<script>
window.jsPDF = window.jspdf.jsPDF;
</script>
}
@(Html.DevExtreme().DataGrid<Company>()
.ID("gridContainer")
.DataSource(new JS("companies"))
.KeyExpr("ID")
.Width("100%")
.ShowBorders(true)
.GroupPanel(groupPanel => groupPanel.Visible(true))
.Grouping(grouping => grouping.AutoExpandAll(true))
.SortByGroupSummaryInfo(i => i.Add().SummaryItem("count"))
.Columns(columns =>
{
columns.Add().DataField("Name").Width(190);
columns.Add().DataField("Address").Width(200);
columns.Add().DataField("City");
columns.Add().DataField("State")
.GroupIndex(0);
columns.Add().DataField("Phone")
.Format(new JS("phoneNumberFormat"));
columns.Add().DataField("Website")
.Alignment(HorizontalAlignment.Center)
.Width(100)
.CellTemplate(@<text>
<a href="<%- value %>" target="_blank">
Website
</a>
</text>);
})
.Summary(s => s
.TotalItems(totalItems =>
{
totalItems.AddFor(m => m.Name)
.SummaryType(SummaryType.Count)
.DisplayFormat("Total count: {0}");
})
)
.Export(e => e.Enabled(true).Formats(new[] { "pdf" }) )
.OnExporting("exportToPDF")
)
<script src="~/Scripts/data/companies.js"></script>
<script>
function exportToPDF(e) {
var doc = new jsPDF();
DevExpress.pdfExporter.exportDataGrid({
jsPDFDocument: doc,
component: e.component,
columnWidths: [40, 40, 30, 30, 40],
customizeCell(options) {
const { gridCell } = options;
const { pdfCell } = options;
if (gridCell.rowType === 'data' && gridCell.column.dataField === 'Phone') {
pdfCell.text = pdfCell.text.replace(/(\d{3})(\d{3})(\d{4})/, '($1) $2-$3');
} else if (gridCell.rowType === 'group') {
pdfCell.backgroundColor = '#BEDFE6';
} else if (gridCell.rowType === 'totalFooter') {
pdfCell.font.style = 'italic';
}
},
customDrawCell(options) {
const { gridCell } = options;
const { pdfCell } = options;
if (gridCell.rowType === 'data' && gridCell.column.dataField === 'Website') {
options.cancel = true;
doc.setFontSize(11);
doc.setTextColor('#0000FF');
const textHeight = doc.getTextDimensions(pdfCell.text).h;
doc.textWithLink('website',
options.rect.x + pdfCell.padding.left,
options.rect.y + options.rect.h / 2 + textHeight / 2, { url: pdfCell.text });
}
},
}).then(() => {
doc.save('Companies.pdf');
});
}
function phoneNumberFormat(value) {
var USNumber = value.match(/(\d{3})(\d{3})(\d{4})/);
return "(" + USNumber[1] + ") " + USNumber[2] + "-" + USNumber[3];
}
</script>
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
In this demo, the customizeCell function changes the following elements:
- Background color and font weight of group row cells
- Font style of a footer cell
The customDrawCell function allows you to draw cells in a PDF document. The following parameters are available when you use this function:
- doc
An instance of the jsPDFDocument object. - rect
A cell’s bounds. - gridCell
Contains information about the source DataGrid cell. - pdfCell
Contains settings applied to a cell in a PDF document. - cancel
Set this parameter to true to prevent default painting logic.
This demo uses the customDrawCell function to paint cells in the "Website" column.