Skip to content

Commit

Permalink
Errors when applying DataTable (#6001)
Browse files Browse the repository at this point in the history
* Errors when applying DataTable

Import correction was made to InputNumber using InputNumberChangeEvent. A type was created for the InputTextArea. Unrecognized characters were removed.

* lint correction. Remove unwanted characters
  • Loading branch information
alanSxSx authored Feb 19, 2024
1 parent 08acd0d commit 66c9da4
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions components/doc/datatable/samples/productsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ import { Rating } from 'primereact/rating';
import { Toolbar } from 'primereact/toolbar';
import { InputTextarea } from 'primereact/inputtextarea';
import { RadioButton, RadioButtonChangeEvent } from 'primereact/radiobutton';
import { InputNumber, InputNumberChangeEvent } from 'primereact/inputnumber';
import { InputNumber,InputNumberValueChangeEvent } from 'primereact/inputnumber';
import { Dialog } from 'primereact/dialog';
import { InputText } from 'primereact/inputtext';
import { Tag } from 'primereact/tag';
Expand Down Expand Up @@ -816,17 +816,27 @@ export default function ProductsDemo() {
let _product = { ...product };
// @ts-ignore
_product[\`\${name}\`] = val;
_product[name] = val;
setProduct(_product);
};
const onInputNumberChange = (e: InputNumberChangeEvent, name: string) => {
const val = e.value || 0;
const onInputTextAreaChange = (e: React.ChangeEvent<HTMLTextAreaElement>, name: string) => {
const val = (e.target && e.target.value) || '';
let _product = { ...product };
// @ts-ignore
_product[\`\${name}\`] = val;
_product[name] = val;
setProduct(_product);
};
const onInputNumberChange = (e: InputNumberValueChangeEvent, name: string) => {
const val = e.value ?? 0;
let _product = { ...product };
// @ts-ignore
_product[name] = val;
setProduct(_product);
};
Expand All @@ -845,7 +855,7 @@ export default function ProductsDemo() {
};
const imageBodyTemplate = (rowData: Product) => {
return <img src={\`https://primefaces.org/cdn/primereact/images/product/\${rowData.image}\`} alt={rowData.image!} className="shadow-2 border-round" style={{ width: '64px' }} />;
return <img src={https://primefaces.org/cdn/primereact/images/product/\${rowData.image}} alt={rowData.image!} className="shadow-2 border-round" style={{ width: '64px' }} />;
};
const priceBodyTemplate = (rowData: Product) => {
Expand Down Expand Up @@ -927,7 +937,9 @@ export default function ProductsDemo() {
}}
dataKey="id" paginator rows={10} rowsPerPageOptions={[5, 10, 25]}
paginatorTemplate="FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink CurrentPageReport RowsPerPageDropdown"
currentPageReportTemplate="Showing {first} to {last} of {totalRecords} products" globalFilter={globalFilter} header={header}>
currentPageReportTemplate="Showing {first} to {last} of {totalRecords} products" globalFilter={globalFilter} header={header}
selectionMode="multiple"
>
<Column selectionMode="multiple" exportable={false}></Column>
<Column field="code" header="Code" sortable style={{ minWidth: '12rem' }}></Column>
<Column field="name" header="Name" sortable style={{ minWidth: '16rem' }}></Column>
Expand All @@ -941,7 +953,7 @@ export default function ProductsDemo() {
</div>
<Dialog visible={productDialog} style={{ width: '32rem' }} breakpoints={{ '960px': '75vw', '641px': '90vw' }} header="Product Details" modal className="p-fluid" footer={productDialogFooter} onHide={hideDialog}>
{product.image && <img src={\`https://primefaces.org/cdn/primereact/images/product/\${product.image}\`} alt={product.image} className="product-image block m-auto pb-3" />}
{product.image && <img src={https://primefaces.org/cdn/primereact/images/product/\${product.image}} alt={product.image} className="product-image block m-auto pb-3" />}
<div className="field">
<label htmlFor="name" className="font-bold">
Name
Expand All @@ -953,7 +965,7 @@ export default function ProductsDemo() {
<label htmlFor="description" className="font-bold">
Description
</label>
<InputTextarea id="description" value={product.description} onChange={(e) => onInputChange(e, 'description')} required rows={3} cols={20} />
<InputTextarea id="description" value={product.description} onChange={(e:ChangeEvent<HTMLTextAreaElement>) => onInputTextAreaChange(e, 'description')} required rows={3} cols={20} />
</div>
<div className="field">
Expand Down

0 comments on commit 66c9da4

Please sign in to comment.