cuốn sách gpt4 ai đã làm

Lưới phản ứng DevExtreme

In lại Tác giả: Vũ trụ không gian Thời gian cập nhật: 2023-11-04 15:25:06 28 4
mua khóa gpt4 Nike

Có ai biết cách thay đổi kích thước phông chữ của TableHeaderRow trong DevExtreme React Grid không?

Đây là trang web tôi luôn sử dụng ( https://devexpress.github.io/devextreme-reactive/react/grid/demos/featured/data-editing/ ) ví dụ mã trong

nhập * dưới dạng React từ 'Reac';
import {
Trạng thái sắp xếp, Trạng thái chỉnh sửa, Trạng thái phân trang,
Phân trang tích hợp, Sắp xếp tích hợp,
} từ '@devexpress/dx-react-grid';
import {
lưới,
Bảng, TableHeaderRow, TableEditRow, TableEditColumn,
PagingPanel, DragDropProvider, Sắp xếp lại cột bảng,
} từ '@devexpress/dx-react-grid-material-ui';
nhập Giấy từ '@material-ui/core/Paper';
nhập Hộp thoại từ '@material-ui/core/Dialog';
nhập DialogActions từ '@material-ui/core/DialogActions';
nhập DialogContent từ '@material-ui/core/DialogContent';
nhập DialogContentText từ '@material-ui/core/DialogContentText';
nhập DialogTitle từ '@material-ui/core/DialogTitle';
Nút nhập từ '@material-ui/core/Button';
nhập IconButton từ '@material-ui/core/IconButton';
nhập Đầu vào từ '@material-ui/core/Input';
nhập Chọn từ '@material-ui/core/Select';
nhập MenuItem từ '@material-ui/core/MenuItem';
nhập TableCell từ '@material-ui/core/TableCell';

nhập DeleteIcon từ '@material-ui/icons/Delete';
nhập EditIcon từ '@material-ui/icons/Edit';
nhập SaveIcon từ '@material-ui/icons/Save';
nhập CancelIcon từ '@material-ui/icons/Cancel';
nhập { withStyles } từ '@material-ui/core/styles';

nhập { ProgressBarCell } từ '../../../theme-sources/material-ui/comComponents/progress-bar-cell';
nhập { HighlightedCell } từ '../../../theme-sources/material-ui/comComponents/highlighted-cell';
nhập { MoneyTypeProvider } từ '../../../theme-sources/material-ui/comComponents/currency-type-provider';
nhập { PercentTypeProvider } từ '../../../theme-sources/material-ui/comComponents/percent-type-provider';

import {
tạoRows,
giá trị bán hàng toàn cầu,
} từ '../../../demo-data/generator';

kiểu const = chủ đề => ({
tra cứuEditCell: {
phần đệmTop: theme.spacing.unit * 0,875,
đệmRight: theme.spacing.unit,
đệmTrái: theme.spacing.unit,
},
hộp thoại: {
chiều rộng: 'calc(100% - 16px)',
},
đầu vàoRoot: {
chiều rộng: '100%',
},
});

const AddButton = ({ onExecute }) => (

<>
màu="chính"
onClick={onExecute}
title="Tạo hàng mới"
>
Mới


);

const EditButton = ({ onExecute }) => (



);

const DeleteButton = ({ onExecute }) => (



);

const CommitButton = ({ onExecute }) => (



);

const CancelButton = ({ onExecute }) => (



);

lệnh constComponents = {
thêm: AddButton,
chỉnh sửa: EditButton,
xóa: Nút xóa,
cam kết: Nút cam kết,
hủy: Nút hủy,
};

const Lệnh = ({ id, onExecute }) => {
const CommandButton = commandComponents[id];
return (

onExecute={onExecute}
/>
);
};

const có sẵnValues ​​​​= {
sản phẩm: GlobalSalesValues.product,
khu vực: toàn cầuSalesValues.khu vực,
khách hàng: GlobalSalesValues.customer,
};

const LookupEditCellBase = ({
có sẵnColumnValues, giá trị, onValueChange, các lớp,
}) => (
<ô>
className={classes.lookupEditCell}
>
<>
giá trị={giá trị}
onChange={event => onValueChange(event.target.value)}
đầu vào={(
<đầu>
class={{ root: class.inputRoot }}
/>
)}
>
{availableColumnValues.map(item => (

{mục}

))}


);
xuất const LookupEditCell = withStyles(styles, { name: 'ControlledModeDemo' })(LookupEditCellBase);

const Cell = (props) => {
const { cột } = đạo cụ;
if (cột.name === 'giảm giá') {
trả về ;
}
if (cột.name === 'số tiền') {
return ;
}
return ;
};

const EditCell = (đạo cụ) => {
const { cột } = đạo cụ;
const availableColumnValues ​​​​= availableValues[column.name];
if (có sẵnColumnValues) {
trả về ;
}
return ;
};

const getRowId = row => row.id;

lớp DemoBase mở rộng React.PureComponent {
constructor(props) {
siêu(đạo cụ);

this.state = {
cột: [
{ tên: 'sản phẩm', tiêu đề: 'Sản phẩm' },
{ tên: 'khu vực', tiêu đề: 'Khu vực' },
{ tên: 'số tiền', tiêu đề: 'Số tiền bán' },
{ tên: 'giảm giá', tiêu đề: 'Giảm giá' },
{ tên: 'saleDate', tiêu đề: 'SaleDate' },
{ tên: 'khách hàng', tiêu đề: 'Khách hàng' },
],
bảngColumnExtensions: [
{ Tên cột: 'số tiền', căn chỉnh: 'đúng' },
],
hàng: generateRows({
cộtValues: { id: ({index }) => chỉ mục, ...globalSalesValues ​​​​},
chiều dài: 12,
}),
sắp xếp: [],
chỉnh sửaRowIds: [],
đã thêmRows: [],
hàngThay đổi: {},
Trang hiện tại: 0,
xóaRows: [],
trangKích thước: 0,
kích thước trang: [5, 10, 0],
cộtĐơn hàng: ['sản ​​phẩm', 'khu vực', 'số tiền', 'giảm giá', 'Ngày giảm giá', 'khách hàng'],
cột tiền tệ: ['số tiền'],
phần trămColumns: ['giảm giá'],
};
const getStateDeletingRows = () => {
const { xóaRows } = this.state;
trả về việc xóaRows;
};
const getStateRows = () => {
const { hàng } = this.state;
trả về hàng;
};

this.changeSorting = sắp xếp => this.setState({ sắp xếp });
this.changeEditingRowIds = editRowIds => this.setState({ editRowIds });
this.changeAddedRows = addedRows => this.setState({
đã thêmRows: addedRows.map(row => (Object.keys(row).length ? row : {
số tiền: 0,
giảm giá: 0,
saleDate: new Date().toISOString().split('T')[0],
sản phẩm: availableValues.product[0],
khu vực: có sẵnValues.khu vực [0],
khách hàng: availableValues.customer[0],
})),
});
this.changeRowChanges = rowChanges => this.setState({ rowChanges });
this.changeCurrentPage = currentPage => this.setState({ currentPage });
this.changePageSize = pageSize => this.setState({ pageSize });
this.commitChanges = ({ đã thêm, đã thay đổi, đã xóa }) => {
hãy để { hàng } = this.state;
nếu (đã thêm) {
const startedAddedId = row.length > 0 ? row[rows.length - 1].id + 1 : 0;
hàng = [
...hàng,
...thêm.map((hàng, chỉ mục) => ({
id: startedAddedId + chỉ mục,
...hàng ngang,
})),
];
}
if (changed) {
row = row.map(row => (đã thay đổi[row.id] ? { ...row, ...changed[row.id] } : row));
}
this.setState({ row, deleteRows: đã xóa || getStateDeletingRows() });
};
this.cancelDelete = () => this.setState({ deleteRows: [] });
this.deleteRows = () => {
const row = getStateRows().slice();
getStateDeletingRows().forEach((rowId) => {
const chỉ số = row.findIndex(row => row.id === rowId);
nếu (chỉ mục > -1) {
row.splice(index, 1);
}
});
this.setState({ hàng, xóaRows: [] });
};
this.changeColumnOrder = (đặt hàng) => {
this.setState({ cộtOrder: order });
};
}

render() {
hằng số {
lớp học,
} = this.props;
hằng số {
hàng,
cột,
bảngColumnExtensions,
sắp xếp,
chỉnh sửaRowIds,
đã thêmHàng,
hàngThay đổi,
trang hiện tại,
xóa hàng,
trangKích thước,
trangKích thước,
cộtThứ tự,
cột tiền tệ,
phần trăm,
} = this.state;

return (

<>
hàng={hàng}
cột={cột}
getRowId={getRowId}
>

sắp xếp={sắp xếp}
onSortingChange={this.changeSorting}
/>

currentPage={currentPage}
onCurrentPageChange={this.changeCurrentPage}
pageSize={pageSize}
onPageSizeChange={this.changePageSize}
/>








editRowIds={editingRowIds}
onEditingRowIdsChange={this.changeEditingRowIds}
rowChanges={rowChanges}
onRowChangesChange={this.changeRowChanges}
đã thêmRows={addRows}
onAddedRowsChange={this.changeAddedRows}
onCommitChanges={this.commitChanges}
/>



<>
cộtExtensions={tableColumnExtensions}
cellComponent={Ô}
/>


thứ tự={columnOrder}
onOrderChange={this.changeColumnOrder}
/>



cellComponent={EditCell}
/>

chiều rộng={120}
showAddCommand={! AddedRows.length}
showChỉnh sửaLệnh
showDeleteCommand
commandComponent={Lệnh}
/>

pageSizes={pageSizes}
/>



open={!!deletingRows.length}
onClose={this.cancelDelete}
class={{ giấy: class.dialog }}
>

Xóa hàng



Bạn có chắc chắn xóa hàng sau không?


<>
row={rows.filter(row => deleteRows.indexOf(row.id) > -1)}
cột={cột}
>


<>
cộtExtensions={tableColumnExtensions}
cellComponent={Ô}
/>










);
}
}

xuất mặc định withStyles(styles, { name: 'ControlledModeDemo' })(DemoBase);

Kích thước phông chữ của văn bản trong các cột được gắn nhãn (ví dụ: sản phẩm, khu vực, số lượng) là cố định và tôi không thấy tham số để thay đổi kích thước đó. Có ý tưởng gì không?

câu trả lời hay nhất

Tôi nghĩ có một số cách để giải quyết vấn đề này, cách tôi sử dụng là có một thành phần được kiểm soát hoàn toàn.

Nó trông hơi giống thế này


trong đó exampleHeaderCell là một thành phần trông như thế này

 Ví dụHeaderCell = (props: bất kỳ) => (<>
className={exampleClass}
{...đạo cụ}
key={column.name}
getMessage={() => cột.title}
/>)

Từ đó bạn có thể truyền cho nó một lớp như trong exampleClass

Bạn có thể tiến thêm một bước nữa và tùy chỉnh cho các cột cụ thể.

Ví dụHeaderCells = (props: bất kỳ) => {
const exampleClass = css({backgroundColor: "blue" })
const { cột } = đạo cụ
if (cột.name === "tên") {
return (
<>
className={exampleClass}
{...đạo cụ}
key={column.name}
getMessage={() => cột.title}
/>
)
}
return colum.title} />
}

Ví dụ trên sẽ trả về ô cụ thể với exampleClass nếu tên cột bằng "name". Nếu không, nó chỉ trả về TableHeaderRow.Cell thông thường

Về javascript - DevExtreme React Grid, chúng tôi đã tìm thấy một câu hỏi tương tự trên Stack Overflow: https://stackoverflow.com/questions/51564801/

28 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress