Datatable not showing indexes
Posted: 24 Sep 2022, 14:48
The data I pulled from the json file does not appear in the datatable. When I look at the components after I put the browser in developer mode, the information in the json appears on the tableHeader side, but the value part on the tablebody side is empty.
The start side of the dashboard.js file
This is The return side of the dashboard.js file
ProductService.js
Example of ozeltarih.json
The start side of the dashboard.js file
Code: Select all
const [ozeltarih, setOzeltarih] = useState(null);
useEffect(() => {
const productService = new ProductService();
productService.getOzelTarih().then((data2) => setOzeltarih(data2));
productService.getMagazalar().then((data) => setProducts(data));
}, []); // eslint-disable-line react-hooks/exhaustive-deps
const onRowEditCompletetarih = (e) => {
let _ozeltarih = [...ozeltarih];
let { newData, index } = e;
_ozeltarih[index] = newData;
setOzeltarih(_ozeltarih);
};
const textEditortarih = (options) => {
return <InputText type="text" value={options.value} onChange={(e) => options.editorCallback(e.target.value)} />;
};
Code: Select all
<DataTable paginator size="small" value={ozeltarih} editMode="row" onRowEditComplete={onRowEditCompletetarih} responsiveLayout="scroll">
<Column field="tarih" header="Tarih" editor={(options) => textEditortarih(options)} style={{ width: "20%" }}></Column>
<Column field="aSaat" header="Açılış Saati" editor={(options) => textEditortarih(options)} style={{ width: "20%" }}></Column>
<Column field="kSaat" header="Kapanış Saati" editor={(options) => textEditortarih(options)} style={{ width: "20%" }}></Column>
<Column rowEditor headerStyle={{ width: "10%", minWidth: "8rem" }} bodyStyle={{ textAlign: "center" }}></Column>
</DataTable>
Code: Select all
getOzelTarih() {
return axios.get('assets/demo/data/ozeltarih.json').then(res => res.data.data);
}
Code: Select all
{
"data": [
{"tarih": "09/08/22", "aSaat": "11:30", "kSaat": "22:00"},
{"tarih": "09/07/22", "aSaat": "11:30", "kSaat": "22:00"}
]
}