I need to show my lookup like this
Lookup image what I want
So the code for this lookup is which is shown is hardcoded but i want to do retrieve data dynamically.
Hardcoded data
I had done with to retrieve data from database and the data is also in same format when i console log the both they are same.
AvaibleMechanic is which we retrieve from DB and dyanmicMechanicLookUp is harcoded
Both data console log SS
setColumnsCode
const [columns, setColumns] = useState([
{ title: "OrderId", field: "_id", editable: "never" },
{ title: "Customer Name", field: "customerName", editable: "never" },
{ title: "Car Name", field: "carName", editable: "never" },
{ title: "Car Number", field: "carNumber", editable: "never" },
{ title: "Address", field: "custAddress", editable: "never" },
{ title: "Service Name", field: "serviceName", editable: "never" },
{ title: "Price", field: "servicePrice", editable: "never" },
{
title: "Assign Mechanic",
field: "mechanicId",
lookup: AvailableMechanic,
},
]);
when i want to see data which is retrieve from Database is not show on the lookup is look like this
Retrieve from database lookup SS
You can see when I used dynamicLookUp which is hardcoded it works fine but when i used data which is retrieve it's not shown on the grid
FullCode
import React, { useState, useEffect } from "react";
import AdminOrders from "../../../services/member/orders.js/admin_orders";
import MechanicService from "../../../services/member/Mechanic/Mechanic_Services";
import "./CSS/Cars.css";
import MaterialTable from "material-table";
import { useSnackbar } from "notistack";
function Orders() {
const [orders, setOrders] = useState([]);
const [completedOrders, setCompletedOrders] = useState([]);
const [AvailableMechanic, setAvailableMechanic] = useState({});
const { enqueueSnackbar, closeSnackbar } = useSnackbar();
//for error handling
const [iserror, setIserror] = useState(false);
const [errorMessages, setErrorMessages] = useState([]);
const getAvailableMechanics = async () => {
await MechanicService.findAvailable()
.then((res) => {
res.map((key,i) => {
setAvailableMechanic(prevState => ({
...prevState,
[key._id]: key.name
}))
})
})
.catch((err) => {
console.log(err)
})
}
const getPlacedOrders = () => {
AdminOrders.findPlacedOrders()
.then((response) => {
setOrders(response);
})
.catch((err) => {
console.log(err);
});
};
const getCompletedOrders = () => {
AdminOrders.findCompletedOrders()
.then((res) => {
setCompletedOrders(res);
})
.catch((err) => {
console.log(err);
});
};
useEffect(() => {
getAvailableMechanics();
getPlacedOrders();
getCompletedOrders();
}, []);
const dynamicMechanicsLookUp = {
'621d06355e364ae391f59af4': "John Doe 1",
'621e3fb9d99ae5efd754b5d6': "John Doe 2",
'62766409db9ad573da5655cc': "John Doe 3",
'6276642cdb9ad573da5655d1': "John Doe 4",
'62766433db9ad573da5655d4': "John Doe 5",
};
// const dynamicMechanicsLookUp = AvailableMechanic;
console.log("dynamicLookUp",dynamicMechanicsLookUp)
console.log("AvailableMechanic",AvailableMechanic)
const [columns, setColumns] = useState([
{ title: "OrderId", field: "_id", editable: "never" },
{ title: "Customer Name", field: "customerName", editable: "never" },
{ title: "Car Name", field: "carName", editable: "never" },
{ title: "Car Number", field: "carNumber", editable: "never" },
{ title: "Address", field: "custAddress", editable: "never" },
{ title: "Service Name", field: "serviceName", editable: "never" },
{ title: "Price", field: "servicePrice", editable: "never" },
{
title: "Assign Mechanic",
field: "mechanicId",
lookup: AvailableMechanic,
},
]);
const [column, setColumn] = useState([
{ title: "OrderId", field: "_id" },
{ title: "Customer Name", field: "customerName" },
{ title: "Car Name", field: "carName" },
{ title: "Car Number", field: "carNumber" },
{ title: "Address", field: "custAddress" },
{ title: "Service Name", field: "serviceName" },
{ title: "Price", field: "servicePrice" },
{ title: "Assigned Mechanic", field: "mechanicId" },
]);
const handleRowUpdate = (newData, oldData, resolve) => {
let errorList = [];
if (errorList.length < 1) {
AdminOrders.assignOrder(newData._id, newData.mechanicId)
.then((res) => {
const dataUpdate = [...orders];
const index = oldData.tableData.id;
dataUpdate[index] = newData;
setOrders([...dataUpdate]);
resolve();
setIserror(false);
setErrorMessages([]);
enqueueSnackbar(res, {
variant: "success",
});
})
.catch((error) => {
setErrorMessages(["Update failed! Server error"]);
setIserror(true);
resolve();
});
} else {
setErrorMessages(errorList);
setIserror(true);
resolve();
}
};
const [display, setdisplay] = useState(false);
const openTable = () => {
setdisplay(true);
};
const closeTable = () => {
setdisplay(false);
};
return (
<div className="cars_container">
<br />
<button onClick={openTable}>See Completed Orders</button>
<br />
{orders ? (
<MaterialTable
title="CURRENT ORDERS DATA"
columns={columns}
data={orders}
editable={{
onRowUpdate: (newData, oldData) =>
new Promise((resolve, reject) => {
handleRowUpdate(newData, oldData, resolve);
}),
}}
options={{
headerStyle: {
backgroundColor: "#01579b",
color: "#FFF",
},
exportButton: true,
}}
/>
) : (
<div>
<br />
<h2>NO CURRENT ORDERS RIGHT NOW</h2>
</div>
)}
<br />
<br />
<br />
{display ? (
<div>
<h1>COMPLETED ORDERS</h1>
<MaterialTable
title="CURRENT ORDERS DATA"
columns={column}
data={completedOrders}
options={{
headerStyle: {
backgroundColor: "#01579b",
color: "#FFF",
},
exportButton: true,
}}
/>
<br />
<button onClick={closeTable}>Close Table</button>
<br />
<br />
<br />
</div>
) : null}
</div>
);
}
export default Orders;
Sorry for the bad english. Please if you find any mistake i am making please let me know
Thanks
Related
I'm trying to create a draggable table with antd, but i always use functionalcomponents in react and all the examples and doc that i found in internet is using class components and that=this stufs like. I don't know how can i use react-drag-listview library with the functional components.
this.state = {
columns: [
{
title: <span className="dragHandler">Key</span>,
dataIndex: "key",
render: (text) => <span>{text}</span>,
width: 50
},
{
title: <span className="dragHandler">Name</span>,
dataIndex: "name",
width: 200
},
{
title: <span className="dragHandler">Gender</span>,
dataIndex: "gender",
width: 100
},
{
title: <span className="dragHandler">Age</span>,
dataIndex: "age",
width: 100
},
{
title: <span className="dragHandler">Address</span>,
dataIndex: "address"
}
]
};
const that = this;
this.dragProps = {
onDragEnd(fromIndex, toIndex) {
const columns = [...that.state.columns];
const item = columns.splice(fromIndex, 1)[0];
columns.splice(toIndex, 0, item);
that.setState({
columns
});
},
nodeSelector: "th",
handleSelector: ".dragHandler",
ignoreSelector: "react-resizable-handle"
};
}
This a small piece of code that I'm trying to copy from, but i don't understand it.
Even an exaple of any small code where i can see how to use with functional components it may work for me.
Tis is the url of the example above: https://codesandbox.io/s/table-column-sortable-resizable-st9bt?file=/index.js
React Drag List View Using Functional Component
import "./index.css";
import { useState } from "react";
import { Resizable } from "react-resizable";
import { Table } from "antd";
import ReactDragListView from "react-drag-listview";
const ResizableTitle = (props) => {
const { onResize, width, ...restProps } = props;
if (!width) {
return <th {...restProps} />;
}
return (
<Resizable
width={width}
height={0}
handle={
<span
className='react-resizable-handle'
onClick={(e) => {
e.stopPropagation();
}}
/>
}
onResize={onResize}
draggableOpts={{ enableUserSelectHack: false }}
>
<th {...restProps} />
</Resizable>
);
};
const data = [
{ key: "1", name: "Boran", gender: "male", age: "12", address: "New York" },
{ key: "2", name: "JayChou", gender: "male", age: "38", address: "TaiWan" },
{ key: "3", name: "Lee", gender: "female", age: "22", address: "BeiJing" },
{ key: "4", name: "ChouTan", gender: "male", age: "31", address: "HangZhou" },
{ key: "5", name: "AiTing", gender: "female", age: "22", address: "Xi’An" },
];
const components = { header: { cell: ResizableTitle } };
const App = () => {
const [columns, setColumns] = useState([
{
title: <span className='dragHandler'>Key</span>,
dataIndex: "key",
render: (text) => <span>{text}</span>,
width: 50,
},
{
title: <span className='dragHandler'>Name</span>,
dataIndex: "name",
width: 200,
},
{
title: <span className='dragHandler'>Gender</span>,
dataIndex: "gender",
width: 100,
},
{
title: <span className='dragHandler'>Age</span>,
dataIndex: "age",
width: 100,
},
{
title: <span className='dragHandler'>Address</span>,
dataIndex: "address",
},
]);
const onDragEnd = (fromIndex, toIndex) => {
setColumns((prev) => {
const nextColumns = [...prev];
const item = nextColumns.splice(fromIndex, 1)[0];
nextColumns.splice(toIndex, 0, item);
return nextColumns;
});
};
const handleResize = (size, index) => {
setColumns((prev) => {
const nextColumns = [...prev];
nextColumns[index] = {
...nextColumns[index],
width: size.width,
};
return nextColumns;
});
};
const tableColumns = columns.map((col, index) => ({
...col,
onHeaderCell: (column) => ({
width: column.width,
onResize: (e, { size }) => handleResize(size, index),
}),
}));
return (
<ReactDragListView.DragColumn
onDragEnd={onDragEnd}
nodeSelector='th'
handleSelector='.dragHandler'
ignoreSelector='react-resizable-handle'
>
<Table bordered columns={tableColumns} dataSource={data} components={components} />
</ReactDragListView.DragColumn>
);
};
export default App;
I'm new to frontend development with React/Redux/Typescript. I'm trying to make the components work. I want to use DataGrid from #mui/material/styles. https://mui.com/x/react-data-grid/.
I have tried searching online but I cannot figure out why I have this error.
My code:
import {
FilteringState,
IntegratedFiltering,
IntegratedPaging,
IntegratedSorting,
PagingState,
Row,
RowDetailState,
SearchState,
SelectionState,
SortingState,
} from "#devexpress/dx-react-grid";
import {
ColumnChooser,
Grid,
PagingPanel,
SearchPanel,
Table,
TableColumnResizing,
TableColumnVisibility,
TableFilterRow,
TableHeaderRow,
Toolbar,
} from "#devexpress/dx-react-grid-material-ui";
import { Card } from "#mui/material";
import { JiraDefect } from "api/classes/JiraDefect";
import { ReactText, useMemo, useState } from "react";
export default function RSADefectsTable(props: {
defects: JiraDefect[];
epicNames: { [key: string]: string };
fixVersions: string[];
}) {
const { defects } = props;
const [selection, setSelection] = useState<ReactText[]>([]);
const [search, setSearch] = useState<string>();
const [defect, setDefect] = useState<string>();
const [open, setOpen] = useState(false);
useMemo(() => {
if (defect) setOpen(true);
}, [defect]);
const [defaultColumnWidths] = useState([
{ columnName: "key", width: 125 },
{ columnName: "created", width: 125 },
{ columnName: "name", width: 500 },
{ columnName: "priority", width: 100 },
{ columnName: "severity", width: 100 },
{ columnName: "status", width: 200 },
{ columnName: "fixVersion", width: 125 },
{ columnName: "components", width: 125 },
{ columnName: "epicLink", width: 175 },
]);
const columns = [
{ name: "key", title: "Key" },
{ name: "created", title: "Created" },
{ name: "name", title: "Headline" },
{ name: "priority", title: "Priority" },
{ name: "severity", title: "Severity" },
{ name: "fixVersion", title: "Fix Version" },
{ name: "status", title: "Status" },
{ name: "components", title: "Component" },
{ name: "epicLink", title: "Epic Name" },
];
const cellValue = (row: JiraDefect, column: string) => {
if (column === "status") return (row[column as keyof JiraDefect] as string).replace(/_/g, " ");
if (column === "priority") return (row[column as keyof JiraDefect] as string).replace(/..- /g, "");
if (column === "created") return row.created.toISOString().slice(0, 10);
if (column === "epicLink" && row.epicLink) return props.epicNames[row.epicLink];
return row[column as keyof JiraDefect];
};
const TableRow = ({ row, ...restProps }: { row: Row }) => (
// eslint-disable-next-line #typescript-eslint/ban-ts-comment
// #ts-ignore
<Table.Row
{...restProps}
onClick={() => {
setDefect(row["key"]);
window.open("https://jira.tooling.intactfc.cloud/browse/" + row["key"]);
}}
style={{ cursor: "pointer" }}
/>
);
const filteredDefects = defects.filter((val) => props.fixVersions.includes(val.fixVersion[0]));
return (
<>
<Card style={{ borderRadius: 10 }}>
<Grid columns={columns} rows={filteredDefects} getCellValue={cellValue}>
<PagingState defaultCurrentPage={0} pageSize={20} />
<SortingState defaultSorting={[{ columnName: "key", direction: "desc" }]} columnSortingEnabled />
<IntegratedSorting />
<SearchState onValueChange={setSearch} value={search} />
<FilteringState />
<RowDetailState />
<SelectionState selection={selection} onSelectionChange={setSelection} />
<IntegratedFiltering />
<IntegratedPaging />
<Toolbar />
<SearchPanel />
<Table rowComponent={TableRow} />
<TableColumnResizing defaultColumnWidths={defaultColumnWidths} />
<TableHeaderRow showSortingControls />
<TableColumnVisibility />
<ColumnChooser />
<TableFilterRow />
<PagingPanel />
</Grid>
</Card>
</>
);
}
Error:
[![enter image description here][1]][1]
Any help will be appreciated.
im trying to fetch customers and trainings by using a fetch request but for some reason it doesn´t print anything in the page. However it is printing those informations in the network console.
import React, { useState, useEffect } from "react";
import Snackbar from '#material-ui/core/Snackbar';
import Addcustomer from "./Addcustomer";
import Addtraining from "./Addtraining";
import Editcustomer from "./Editcustomer";
import { AgGridReact } from'ag-grid-react'
import'ag-grid-community/dist/styles/ag-grid.css'
import'ag-grid-community/dist/styles/ag-theme-material.css';
export default function Customerlist() {
const [customers, setCustomers] = useState([]);
useEffect(() => fetchData(), []);
const fetchData = () => {
fetch('https://customerrest.herokuapp.com/api/customers')
.then(response => response.json())
.then(data => setCustomers(data.content));
};
const deleteCustomer = link => {
if (window.confirm("Are you sure to delete customer?")) {
console.log(link);
fetch(link, { method: "DELETE" })
.then(res => {
fetchData();
if (res.status >= 200 && res.status < 300) {
Snackbar({ message: "Customer deleted successfully" });
} else {
Snackbar({ message: "Error. Try again." });
}
})
.catch(err => console.error(err));
}
};
const saveCustomer = customer => {
fetch('https://customerrest.herokuapp.com/api/customers', {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(customer)
})
.then(res => {
fetchData();
if (res.status >= 200 && res.status < 300) {
Snackbar({ message: "Customer added successfully" });
} else {
Snackbar({ message: "Error. Try again." });
}
})
.catch(err => console.error(err));
};
const saveTraining = training => {
fetch('https://customerrest.herokuapp.com/api/trainings', {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(training)
})
.then(res => {
fetchData();
if (res.status >= 200 && res.status < 300) {
Snackbar({ message: "Training added successfully" });
} else {
Snackbar({ message: "Error. Try again." });
}
})
.catch(err => console.error(err));
};
const updateCustomer = (customer, link) => {
fetch(link, {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(customer)
})
.then(res => fetchData())
.then(Snackbar({ message: "Customer updated successfully" }))
.catch(err => console.error(err));
};
const columns = [
{
title: "Edit",
field: "links[0].href",
render: customerData => (
<Editcustomer updateCustomer={updateCustomer} customer={customerData} />
),
sorting: false
},
{
Header: "First name",
accessor: "firstname"
},
{
Header: "Last name",
accessor: "lastname"
},
{
Header: "Email",
accessor: "email"
},
{
Header: "Phone",
accessor: "phone"
},
{
Header: "Address",
accessor: "streetaddress"
},
{
Header: "Postcode",
accessor: "postcode"
},
{
Header: "City",
accessor: "city"
},
{
title: "Delete",
field: "links[0].href",
render: customerData => (
<button
style={{ cursor: "pointer" }}
onClick={() => deleteCustomer(customerData.links[0].href)}
>Delete</button>
),
sorting: false
},
{
title: "Add training",
render: trainingRow => (
<Addtraining
saveTraining={saveTraining}
customerId={trainingRow.links[0].href}
/>
),
sorting: false
}
];
return (
<div>
<Addcustomer saveCustomer={saveCustomer} />
<AgGridReact
title="Customers"
rowData={customers}
columns={columns}
options={{ sorting: true }}
></AgGridReact>
</div>
);
}
i have multiple fetch requests for training and customers but its not working
it shows the information in the console but it doesn't show them in the page. I would like to see all the information in my page, so what i have to do or what did i do wrong here?
The props passed to AgGridReact component are not the right type.
columnDefs prop is used to declare the column headers and should look like:
const columnDefs = [
{ headerName: 'Customers',
children: [
{
headerName: 'Edit',
valueGetter: (params) => params.data.links[0].href,
cellRenderer: (params) => <Editcustomer updateCustomer={updateCustomer} customer={params.data} />,
sortable: false,
},
{
headerName: 'First name',
field: 'firstname',
},
{
headerName: 'Last name',
field: 'lastname',
},
{
headerName: 'Email',
field: 'email',
},
{
headerName: 'Phone',
field: 'phone',
},
{
headerName: 'Address',
field: 'streetaddress',
},
{
headerName: 'Postcode',
field: 'postcode',
},
{
headerName: 'City',
field: 'city',
},
{
headerName: 'Delete',
valueGetter: (params) => params.data.links[0].href,
cellRenderer: (params) => (
<button style={{ cursor: 'pointer' }} onClick={() => deleteCustomer(params.data.links[0].href)}>
Delete
</button>
),
sortable: false,
},
{
headerName: 'Add training',
valueGetter: (params) => params.data.links[0].href,
cellRenderer: (params) => (
<Addtraining
saveTraining={saveTraining}
customerId={params.data.links[0].href}
/>
),
sortable: false,
},
]
}];
defaultColDef prop is used to declare defaults for the column headers.
const defaultColDef={ sortable: true }
Your implementation of the AgGridReact element should be:
<AgGridReact
rowData={customers}
columnDefs={columnDefs}
defaultColDef={defaultColDef}
></AgGridReact>
Finally, you need to either set the domLayout prop so that the grid size is autocomputed (ideally for very small datasets).
<AgGridReact
rowData={customers}
columnDefs={columnDefs}
defaultColDef={defaultColDef}
domLayout='autoHeight'
></AgGridReact>
Otherwise, you can set the size of the container element so that the grid size is computed from it.
<div
style={{
height: '500px',
width: '600px',
}}
>
<AgGridReact
rowData={customers}
columnDefs={columnDefs}
defaultColDef={defaultColDef}
></AgGridReact>
</div>
you need to conditionaly render the information when the data is ready and you need to map on every object
const [customers, setCustomers] = useState([]);
useEffect(() => fetchData(), []);
return (
<>
{customers && customers.map((obj, i) => (
<div key={i}>
<p>{obj.firstname}</p>
<p>{obj.lastname}</p>
</div>
)}
</>
)
your displaying data is more complicated because you use other components "Addcustomer", "AgGridReact" but im just showing how to basically get the data into html
I want to export data from ej2 syncfusion react data grid to Excel and PDF, but the existing data has some details related to each row. I want to export the following data with detailed data into Excel and PDF. Is there any way to export grid with Detailed Row in ej2 Syncfusion React Data Grid? I tried to use hierarchyExportMode at Export Properties and its not working to export the detail row, only the main data in the row.
Here's the data I want to export
sample pic:
import React from 'react';
import { Layout } from 'antd';
import dummyParrent from '../../../../dataDummy4.json';
import dummyAnak from '../../../../dataDummy5.json';
import {
GridComponent,
ColumnDirective,
ColumnsDirective,
Page,
Inject,
Toolbar,
PdfExport,
Grid,
ExcelExport,
Filter,
DetailRow,
} from '#syncfusion/ej2-react-grids'
import { DataManager, Query } from '#syncfusion/ej2-data';
const Laporan = () => {
const { Content } = Layout;
let grid = Grid | null;
const dataParrent = dummyParrent.map((dt, index) => {
return ({
no: index + 1,
id_team: dt.id_team,
nama_team: dt.nama_team,
adviser: dt.adviser
})
})
const dataAnak = dummyAnak.map((dt) => {
return ({
id: dt.id,
nama: dt.nama,
umur: dt.umur,
col_dum: dt.col_dum,
id_team: dt.id_team
})
})
const detailData = (e) => {
const selectData = new DataManager(dataAnak).executeLocal(new Query().where("id_team", "equal", e.data.id_team, false));
const detail1 = new Grid({
dataSource: selectData,
columns: [
{ field: 'id', headerText: 'Id ', width: 100 },
{ field: 'nama', headerText: 'Nama', width: 100 },
{ field: 'umur', headerText: 'Umur', width: 100 },
{ field: 'col_dum', headerText: 'Col_dum', width: 100 },
{ field: 'id_team', headerText: 'Id Team', width: 100 }
]
});
const detail2 = new Grid({
dataSource: selectData,
columns: [
{ field: 'id', headerText: 'Id ', width: 100 },
{ field: 'nama', headerText: 'Nama', width: 100 },
{ field: 'umur', headerText: 'Umur', width: 100 },
{ field: 'col_dum', headerText: 'Col_dum', width: 100 },
{ field: 'id_team', headerText: 'Id Team', width: 100 }
]
});
detail1.appendTo(e.detailElement.querySelector('.custom-grid1'));
detail2.appendTo(e.detailElement.querySelector('.custom-grid2'));
}
const gridTemplate = () => {
return (
<div className='mt-2'>
<div className='mb-2'>
<b>Detail Data 1</b>
<div className='custom-grid1'></div>
</div>
<div className=''>
<b>Detail Data 2</b>
<div className='custom-grid2'></div>
</div>
</div>
);
}
const toolbarClick = (args) => {
if (grid) {
if (args.item.id.includes('excelexport')) {
grid.excelExport({
fileName: 'ExportHirarki.xlsx',
hierarchyExportMode: 'All',
}
})
} else if (args.item.id.includes('pdfexport')) {
grid.pdfExport({
fileName: 'ExportHirarki.pdf',
hierarchyExportMode: 'All',
pageSize: 'A4',
pageOrientation: 'Landscape'
})
}
}
}
const pdfHeaderQueryCellInfo = (PdfHeaderQueryCellInfoEventArgs) => {
PdfHeaderQueryCellInfoEventArgs.cell.row.pdfGrid.repeatHeader = true;
}
return (
<Content className='konten'>
<div>
<div className='mt-2'><b>First Grid</b></div>
<GridComponent
dataSource={dataParrent}
ref={g => grid = g}
allowPaging={true}
toolbar={['PdfExport', 'ExcelExport', 'Search']}
allowPdfExport={true}
allowExcelExport={true}
allowFiltering={true}
filterSettings={{ type: 'Excel' }}
toolbarClick={toolbarClick}
pdfHeaderQueryCellInfo={pdfHeaderQueryCellInfo}
gridLines='Both'
width='auto'
dataBound={() => {
grid.detailRowModule.expandAll()
}}
detailDataBound={detailData}
detailTemplate={gridTemplate}
>
<ColumnsDirective>
<ColumnDirective field='no' headerText='No' textAlign='Left' headerTextAlign='Center' width='120' />
<ColumnDirective field='id_team' headerText='Id Team' textAlign='Left' headerTextAlign='Center' width='120' />
<ColumnDirective field='nama_team' headerText='Nama Team' textAlign='Left' headerTextAlign='Center' width='120' />
<ColumnDirective field='adviser' headerText='Adviser' textAlign='Left' headerTextAlign='Center' width='150' />
</ColumnsDirective>
<Inject services={[Page, Toolbar, PdfExport, ExcelExport, Filter, DetailRow]} />
</GridComponent>
</div>
</Content>
);
};
export default Laporan;
Here is dataDummy4.json:
[
{
"id_team": "1",
"nama_team": "IYO A",
"adviser": "Dummy"
},
{
"id_team": "2",
"nama_team": "IYO B",
"adviser": "Dummy"
},
{
"id_team": "1",
"nama_team": "IYO C",
"adviser": "Dummy"
},
{
"id_team": "2",
"nama_team": "IYO D",
"adviser": "Dummy"
}
]
And dataDummy5.json:
[
{
"id_team": "1",
"id": "5",
"nama": "Child 1",
"umur": "22",
"status": "Single 1",
"col_dum": "Hellow World"
},
{
"id_team": "2",
"id": "6",
"nama": "Child 2",
"umur": "25",
"status": "Single 2",
"col_dum": "Hellow World"
},
{
"id_team": "2",
"id": "7",
"nama": "Child Baru",
"umur": "25",
"status": "Single Baru",
"col_dum": "Hellow World"
}
]
The EJ2 Grid does not support the detail template exporting as the template may contain anything(text, image, etc.). So, if you want to export the data as the main Grid and child Grid pattern, then you can use the hierarchy grid export.
PdfExport
ExcelExport
Demo
when i use editable attribute in schema
editable: (row, rowData) => {
return rowData.town === "scaraborough";
},
it works fine but when i use celEdit editable property of field just working with boolean
const tableRef = React.useRef();
const [columns, setColumns] = useState<Column<schema>[]>([
{
title: "Name",
field: "name",
editable: "always",
type: "string",
resizable: true,
emptyValue: <div style={{ visibility: "hidden" }}>empty</div>,
},
{
title: "Town",
field: "town",
editable: (row, rowData) => {
return rowData.town === "scaraborough";
},
type: "string",
},
{
title: "Digits",
field: "digits",
type: "numeric",
lookup: { 63: "212", 212: "1212" },
},
{ title: "status", field: "status", editable: "always", type: "boolean" },
]);
const [data, setData] = useState<schema[]>([
{
name: "",
town: "sample input data",
digits: 63,
status: false,
},
{ name: "jimmy", town: "scaraborough", digits: 63, status: false },
{ name: "sdsdd", town: "china", digits: 212, status: false },
]);
const options = { filtering: true, selection: true };
return (
<MaterialTable
tableRef={tableRef}
columns={columns}
data={data}
options={options}
// editable={{
// onRowUpdate: (newData, oldData) =>
// new Promise((resolve, reject) => {
// const dataUpdate = [...data];
// resolve(data);
// }),
// }}
cellEditable={{
onCellEditApproved: (newValue, oldValue, rowData: any, columnDef) => {
return new Promise((resolve, reject) => {
resolve();
});
},
}}
/>
);
"material-table": "^1.69.3",