Unable to write more than 1 digit in number cell #545
Unanswered
sajjadalidev
asked this question in
Q&A
Replies: 1 comment 1 reply
-
|
Uncaught TypeError: Cannot read properties of undefined (reading '0') |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
`import { useState, useEffect } from "react";
import { ReactGrid } from "@silevis/reactgrid";
import "@silevis/reactgrid/styles.css";
import "./style.css";
import { Modal, Button } from "react-bootstrap";
import { useLocation } from "react-router-dom/cjs/react-router-dom";
import { getSettingKey } from "../../../../../../Common/utils";
import { shallowEqual, useSelector } from "react-redux";
function NewSpreadSheet({ show, onHide, products, setFieldValue, quntityAndDiscountNotEditable }) {
const [productslist, setProducts] = useState(products || []);
const [originalProducts, setOriginalProducts] = useState(products || []);
const [searchTerm, setSearchTerm] = useState("");
const { currentBasicState } = useSelector((state) => ({ currentBasicState: state.basicSettings }), shallowEqual);
const currencySymbol = getSettingKey(currentBasicState.entity, "Basic", "currency_symbol");
const getColumns = () => [
{ columnId: "name", width: 400, resizable: true, editor: null },
{ columnId: "newPrice", width: 100, resizable: true, reorderable: true },
{ columnId: "quantity", width: 75, resizable: true, reorderable: true },
{ columnId: "discount", width: 100, resizable: true, reorderable: true },
{ columnId: "sku", width: 100, resizable: true, editor: null },
{ columnId: "upc", width: 175, resizable: true, editor: null },
{ columnId: "main_category_name", width: 200, resizable: true, editor: null },
{ columnId: "brand_name", width: 200, resizable: true, editor: null },
];
const headerRow = {
rowId: "header",
cells: [
{ type: "header", text: "Name" },
{ type: "header", text:
Price(${currencySymbol})},{ type: "header", text: "Quantity" },
{ type: "header", text:
Discount(${currencySymbol})},{ type: "header", text: "SKU" },
{ type: "header", text: "UPC" },
{ type: "header", text: "Main Category" },
{ type: "header", text: "Brand" },
],
};
const getFilteredProductsWithIndices = (products) => {
return (
products
?.map((product, originalIndex) => ({ product, originalIndex }))
.filter(({ product }) => {
const searchTermLower = searchTerm.toLowerCase().trim();
if (!searchTermLower) return true;
};
const getRows = (products) => {
const filteredProductsWithIndices = getFilteredProductsWithIndices(products);
};
const applyChangesToProduct = (changes, prevProduct) => {
debugger;
const updatedProducts = [...prevProduct];
changes.forEach((change) => {
// Parse the original index from rowId (which is now a string)
const productIndex = parseInt(change.rowId, 10);
const fieldName = change.columnId;
};
const handleChanges = (changes) => {
// Only allow changes for editable columns
const editableColumns = ["discount", "newPrice", "quantity"];
const filteredChanges = changes.filter((change) => editableColumns.includes(change.columnId));
if (filteredChanges?.length > 0) {
setProducts((prevProduct) => applyChangesToProduct(filteredChanges, prevProduct));
}
};
const columns = getColumns();
const columnConfig = [
{ columnId: "name", editor: null },
{ columnId: "sku", editor: null },
{ columnId: "upc", editor: null },
{ columnId: "main_category_name", editor: null },
{ columnId: "brand_name", editor: null },
];
// Check if any products match the search term
const filteredRows = getFilteredProductsWithIndices(productslist);
const handleCancel = () => {
// Reset to original products with deep clone
setProducts(deepClone(originalProducts));
setSearchTerm("");
onHide();
};
// Deep clone function to avoid reference issues
const deepClone = (obj) => {
if (obj === null || typeof obj !== "object") return obj;
if (obj instanceof Date) return new Date(obj);
if (Array.isArray(obj)) return obj.map((item) => deepClone(item));
return Object.keys(obj).reduce((cloned, key) => {
cloned[key] = deepClone(obj[key]);
return cloned;
}, {});
};
// Reset data when modal opens
useEffect(() => {
if (show) {
const clonedProducts = deepClone(products || []);
setOriginalProducts(clonedProducts);
setProducts(clonedProducts);
setSearchTerm("");
}
}, [show]);
return (
<Modal.Header>
<Modal.Title>Products</Modal.Title>
<Button
variant="secondary"
onClick={() => {
setFieldValue("sale_order_details", productslist);
onHide();
}}
className="mx-4"
>
Save Changes
Cancel
</Modal.Header>
<Modal.Body className="custom-modal-body">
<label
className="form-label text-xl"
style={{ fontSize: "16px", fontWeight: "500", position: "sticky", top: 0, zIndex: 10, paddingTop: "10px", paddingBottom: "10px" }}
>
Search by product name/brand/category
<input
type="text"
placeholder="Search by product name/brand/category"
value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)}
className="mb-3 form-control"
style={{ width: "50%", fontSize: "18px" }}
/>
{filteredRows?.length === 0 ? (
) : (
)}
</Modal.Body>
);
}
export default NewSpreadSheet;
`
Here is my component, but its working very wiered. sometime working fine but sometime it showing me an error
Beta Was this translation helpful? Give feedback.
All reactions