Skip to content

Commit cf644da

Browse files
Fix TS in Vue demos. Grids (#30886)
1 parent 3ffde5f commit cf644da

File tree

35 files changed

+179
-114
lines changed

35 files changed

+179
-114
lines changed

apps/demos/Demos/DataGrid/AdvancedMasterDetailView/Vue/ProductSelectBox.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ const dataSource = createStore({
3333
onLoaded: setDefaultValue,
3434
});
3535
36-
const productId = ref(null);
36+
const productId = ref<number>();
3737
3838
function setDefaultValue(items: Product[]) {
3939
const firstItem = items[0];
4040
41-
if (firstItem && productId.value === null) {
41+
if (firstItem && productId.value === undefined) {
4242
productId.value = firstItem.ProductID;
4343
}
4444
}

apps/demos/Demos/DataGrid/BatchUpdateRequest/Vue/App.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ async function processBatchRequest(
8282
url: string, changes: DxDataGridTypes.DataChange[], component: DxDataGrid['instance'],
8383
) {
8484
await sendBatchRequest(url, changes);
85-
await component.refresh(true);
85+
await component?.refresh(true);
8686
87-
component.cancelEditData();
87+
component?.cancelEditData();
8888
}
8989
9090
async function sendBatchRequest(url: string, changes: DxDataGridTypes.DataChange[]) {

apps/demos/Demos/DataGrid/CommandColumnConfiguration/Vue/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ const isChief = (position: string) => position && ['CEO', 'CMO'].indexOf(positio
8181
8282
const isCloneIconVisible = (e: { row: DxDataGridTypes.Row }) => !e.row.isEditing;
8383
84-
const isCloneIconDisabled = (e: { row: DxDataGridTypes.Row }) => isChief(e.row.data.Position);
84+
const isCloneIconDisabled = (e: { row: DxDataGridTypes.Row }) => !!isChief(e.row.data.Position);
8585
8686
const isDeleteIconVisible = (e: { row: DxDataGridTypes.Row }) => !isChief(e.row.data.Position);
8787

apps/demos/Demos/DataGrid/CustomEditors/Vue/App.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,14 @@ const onRowInserted = (e: DxDataGridTypes.RowInsertedEvent) => {
146146
function calculateFilterExpression(
147147
this: DxDataGridTypes.Column,
148148
filterValue: any,
149-
selectedFilterOperations: string,
149+
selectedFilterOperations: string | null,
150150
target: string,
151-
): any {
151+
) {
152152
if (target === 'search' && typeof filterValue === 'string') {
153153
return [this.dataField, 'contains', filterValue];
154154
}
155155
156-
return (rowData: Task) => (rowData.AssignedEmployee || []).includes(filterValue);
156+
return ((rowData: Task) => (rowData.AssignedEmployee || []).includes(filterValue)) as () => any;
157157
}
158158
</script>
159159
<style>

apps/demos/Demos/DataGrid/CustomEditors/Vue/EmployeeTagBoxComponent.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const props = defineProps<{
2929
const currentValue = ref(props.cellInfo.value);
3030
3131
const onSelectionChanged = () => {
32-
props.dataGridComponent.updateDimensions();
32+
props.dataGridComponent?.updateDimensions();
3333
};
3434
3535
const onValueChanged = (e: DxTagBoxTypes.ValueChangedEvent) => {

apps/demos/Demos/DataGrid/DeferredSelection/Vue/App.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ const peopleCount = ref(0);
102102
const avgDuration = ref(0);
103103
104104
const calculateStatistics = async() => {
105+
if (!dataGrid) return;
106+
105107
const selectedItems = await dataGrid.getSelectedRowsData();
106108
107109
const totalDuration = selectedItems.reduce((currentValue, item) => {

apps/demos/Demos/DataGrid/ExcelJSCellCustomization/Vue/App.vue

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ import { Workbook } from 'devextreme-exceljs-fork';
7474
// Our demo infrastructure requires us to use 'file-saver-es'.
7575
// We recommend that you use the official 'file-saver' package in your applications.
7676
import { saveAs } from 'file-saver-es';
77-
import { exportDataGrid } from 'devextreme-vue/common/export/excel';
77+
import { exportDataGrid, type DataGridCell } from 'devextreme-vue/common/export/excel';
7878
import { companies } from './data.ts';
7979
8080
const onExporting = (e: DxDataGridTypes.ExportingEvent) => {
@@ -90,22 +90,22 @@ const onExporting = (e: DxDataGridTypes.ExportingEvent) => {
9090
worksheet,
9191
keepColumnWidths: false,
9292
topLeftCell: { row: 2, column: 2 },
93-
customizeCell: ({ gridCell, excelCell }) => {
94-
if (gridCell.rowType === 'data') {
95-
if (gridCell.column.dataField === 'Phone') {
93+
customizeCell: ({ gridCell, excelCell }: { gridCell?: DataGridCell, excelCell?: any }) => {
94+
if (gridCell?.rowType === 'data') {
95+
if (gridCell.column?.dataField === 'Phone') {
9696
excelCell.value = parseInt(gridCell.value, 10);
9797
excelCell.numFmt = '[<=9999999]###-####;(###) ###-####';
9898
}
99-
if (gridCell.column.dataField === 'Website') {
99+
if (gridCell.column?.dataField === 'Website') {
100100
excelCell.value = { text: gridCell.value, hyperlink: gridCell.value };
101101
excelCell.font = { color: { argb: 'FF0000FF' }, underline: true };
102102
excelCell.alignment = { horizontal: 'left' };
103103
}
104104
}
105-
if (gridCell.rowType === 'group') {
105+
if (gridCell?.rowType === 'group') {
106106
excelCell.fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'BEDFE6' } };
107107
}
108-
if (gridCell.rowType === 'totalFooter' && excelCell.value) {
108+
if (gridCell?.rowType === 'totalFooter' && excelCell.value) {
109109
excelCell.font.italic = true;
110110
}
111111
},

apps/demos/Demos/DataGrid/ExcelJSExportImages/Vue/App.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import { Anchor, Workbook } from 'devextreme-exceljs-fork';
4747
// Our demo infrastructure requires us to use 'file-saver-es'.
4848
// We recommend that you use the official 'file-saver' package in your applications.
4949
import { saveAs } from 'file-saver-es';
50-
import { exportDataGrid } from 'devextreme-vue/common/export/excel';
50+
import { type DataGridCell, exportDataGrid } from 'devextreme-vue/common/export/excel';
5151
import { employees } from './data.ts';
5252
5353
const onExporting = (e: DxDataGridTypes.ExportingEvent) => {
@@ -59,9 +59,9 @@ const onExporting = (e: DxDataGridTypes.ExportingEvent) => {
5959
worksheet,
6060
autoFilterEnabled: true,
6161
topLeftCell: { row: 2, column: 2 },
62-
customizeCell: ({ gridCell, excelCell }) => {
63-
if (gridCell.rowType === 'data') {
64-
if (gridCell.column.dataField === 'Picture') {
62+
customizeCell: ({ gridCell, excelCell }: { gridCell?: DataGridCell, excelCell?: any }) => {
63+
if (gridCell?.rowType === 'data') {
64+
if (gridCell.column?.dataField === 'Picture') {
6565
excelCell.value = undefined;
6666
6767
const image = workbook.addImage({

apps/demos/Demos/DataGrid/ExcelJSExportMultipleGrids/Vue/App.vue

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,16 @@
8080
</template>
8181
<script setup lang="ts">
8282
import { ref } from 'vue';
83+
// Our demo infrastructure requires us to use 'file-saver-es'.
84+
// We recommend that you use the official 'file-saver' package in your applications.
85+
import { saveAs } from 'file-saver-es';
8386
import DxButton from 'devextreme-vue/button';
8487
import DxTabPanel, { DxItem } from 'devextreme-vue/tab-panel';
8588
import { DxDataGrid, DxColumn } from 'devextreme-vue/data-grid';
86-
8789
import { Workbook } from 'devextreme-exceljs-fork';
88-
// Our demo infrastructure requires us to use 'file-saver-es'.
89-
// We recommend that you use the official 'file-saver' package in your applications.
90-
import { saveAs } from 'file-saver-es';
91-
import { type DataGridCell, exportDataGrid } from 'devextreme-vue/common/export/excel';
90+
import { type DataGridCell as ExelDataGridCell, exportDataGrid } from 'devextreme-vue/common/export/excel';
9291
import { type DataSourceOptions } from 'devextreme-vue/common/data';
9392
94-
import 'devextreme-vue/common/data';
95-
9693
const priceGridRef = ref<DxDataGrid | null>(null);
9794
const ratingGridRef = ref<DxDataGrid | null>(null);
9895
@@ -132,15 +129,19 @@ const exportGrids = () => {
132129
worksheet: priceSheet,
133130
component: priceGridRef.value?.instance,
134131
topLeftCell: { row: 4, column: 2 },
135-
customizeCell: ({ gridCell, excelCell }) => {
136-
setAlternatingRowsBackground(gridCell, excelCell);
132+
customizeCell: ({ gridCell, excelCell }: { gridCell?: ExelDataGridCell, excelCell?: any }) => {
133+
if (gridCell) {
134+
setAlternatingRowsBackground(gridCell, excelCell);
135+
}
137136
},
138137
}).then(() => exportDataGrid({
139138
worksheet: ratingSheet,
140139
component: ratingGridRef.value?.instance,
141140
topLeftCell: { row: 4, column: 2 },
142-
customizeCell: ({ gridCell, excelCell }) => {
143-
setAlternatingRowsBackground(gridCell, excelCell);
141+
customizeCell: ({ gridCell, excelCell }: { gridCell?: ExelDataGridCell, excelCell?: any }) => {
142+
if (gridCell) {
143+
setAlternatingRowsBackground(gridCell, excelCell);
144+
}
144145
},
145146
})).then(() => {
146147
workbook.xlsx.writeBuffer().then((buffer) => {
@@ -149,7 +150,7 @@ const exportGrids = () => {
149150
});
150151
};
151152
152-
const setAlternatingRowsBackground = (gridCell: DataGridCell, excelCell: any) => {
153+
const setAlternatingRowsBackground = (gridCell: ExelDataGridCell, excelCell: any) => {
153154
if (gridCell.rowType === 'header' || gridCell.rowType === 'data') {
154155
if (excelCell.fullAddress.row % 2 === 0) {
155156
excelCell.fill = {

apps/demos/Demos/DataGrid/ExcelJSHeaderAndFooter/Vue/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ const onExporting = (e: DxDataGridTypes.ExportingEvent) => {
9090
headerRow.getCell(1).alignment = { horizontal: 'center' };
9191
9292
// footer
93-
const footerRowIndex = cellRange.to.row + 2;
93+
const footerRowIndex = (cellRange.to?.row || 0) + 2;
9494
const footerRow = worksheet.getRow(footerRowIndex);
9595
worksheet.mergeCells(footerRowIndex, 1, footerRowIndex, 8);
9696

0 commit comments

Comments
 (0)