After installing the Material Table using React JS and mapping the data to it, this error will be displayed on the console while running the application. The reason for this is hard for me to imagine.
Below is the table I developed.
`
const empList = [
{ id: 1, name: "Neeraj", email: 'neeraj#gmail.com', phone: 9876543210, city: "Bangalore" },
{ id: 2, name: "Raj", email: 'raj#gmail.com', phone: 9812345678, city: "Chennai" },
{ id: 3, name: "David", email: 'david342#gmail.com', phone: 7896536289, city: "Jaipur" },
{ id: 4, name: "Vikas", email: 'vikas75#gmail.com', phone: 9087654321, city: "Hyderabad" },
]
const [data, setData] = useState(empList)
const columns = [
{ title: "ID", field: "id", editable: false },
{ title: "Name", field: "name" },
{ title: "Email", field: "email" },
{ title: "Phone Number", field: 'phone', },
{ title: "City", field: "city", }
]
<h5>
List of Services
</h5>
<MaterialTable
title="Employee Data"
data={data}
columns={columns}
/>
</div>`
I have also encountered the same bug and it seems that they haven't covered the case that no theming is provided. So, in order for the MaterialTable to work properly you need at least the following implementation:
import * as React from 'react';
import MaterialTable from 'material-table';
import { ThemeProvider, createTheme } from '#mui/material';
export class DataGridReact extends React.Component {
public render(): JSX.Element {
const defaultMaterialTheme = createTheme();
return(
<div style={{ width: '100%', height: '100%' }}>
<link
rel="stylesheet"
href="https://fonts.googleapis.com/icon?family=Material+Icons"
/>
<ThemeProvider theme={defaultMaterialTheme}>
<MaterialTable
columns={[
{ title: 'Name', field: 'name' },
{ title: 'Surname', field: 'surname' },
{ title: 'Birth Year', field: 'birthYear', type: 'numeric' },
{ title: 'Birth City', field: 'birthCity', lookup: { 1: 'Linz', 2: 'Vöcklabruck', 3: 'Salzburg' } }
]}
data={[
{ name: 'Max', surname: 'Mustermann', birthYear: 1987, birthCity: 1 },
{ name: 'Cindy', surname: 'Musterfrau', birthYear: 1995, birthCity: 2 }
]}
title="Personen"
/>
</ThemeProvider>
</div>
);
}
}
So I figured out the solution. If your current version of material table is 2.0.3, just uninstall your version and re-install version 1.69.3. This will solve the issue, it worked for me. They have released the 2.0.3 version quite recently (10 days back) and it seems to have bugs and I guess that's the reason why you and me faced issues.
I tried all possible things but it seems to have a problem with the material-table package itself. I tried to install the v1.69.3 also, but then it showed some 19 errors all of which were from the Metrial-Table Package,
which shows that it is really buggy. With some other versions it showed some 20 errors all from the package itself, these errors were silenced after I reinstall #material-ui/core as mentioned on their website https://material-table.com/#/docs/install:~:text=npm%20install%20material%2Dtable%20%2D%2Dsave%0Anpm%20install%20%40material%2Dui/core%20%2D%2Dsave, But the problem that the table is not showing is still there.
Finally installing the very old release having dependency of react version older than 16, helped me.
You can run :
npm uninstall material-table
then run following:
npm install material-table#1.36.0 --save
and then check if it works,
if not try to run
npm install #material-ui/core --save
or
npm install in the terminal.
I hope it will work for you to help you get running, but I noticed though the table shows but it disturbs some functionlaity of material ui itself.
So i had the same problem on some pcs and not on others. Figured out the issue was due to the node js version. so the following worked for me:
changing to material-table version to 1.69.3 or 1.36.0 works but it was
messing up the styling of my other mui components. So shifted back to
material-table 2.0.3
I was using node version 14.19.0 so changed it to 16.5.1 using nvm.
delete the node modules completely shift+ delete
npm i to install all dependencies.(remember during this step the node
version should be 16.5 , so check once using node -v)
npm start
I updated mui's packages, using:
yarn upgrade #mui/icons-material #mui/material #mui/styles --latest since I was using material-table 2.0.2.
then don't froget to wrap the table with the ThemeProvider: ( THANKS #nikried FOR your answer, it was very helpful! )
import * as React from 'react';
import MaterialTable from 'material-table';
import { ThemeProvider, createTheme } from '#mui/material';
export function SimpleExample () {
const defaultMaterialTheme = createTheme();
return(
<div style={{ width: '100%', height: '100%' }}>
<ThemeProvider theme={defaultMaterialTheme}>
<MaterialTable
columns={columns}
data={data}
/>
</ThemeProvider>
</div>
);
}
}
if you have other problems, don't forget to check the peerDependencies of material-table inside node_modules, and try to use the same package's version montioned to avoid all the possible conflicts.
Related
I am trying to use 'material-table' in my Material dashboard 2 pro react dashboard by Creative Tim, but while adding the data in the table, the data is not aligned with the and has a lot of gaps.
My component code:
import { Grid } from "#mui/material";
import MaterialTable from "material-table";
import EditableTable from "examples/Tables/EditableTable";
function AdminTable() {
return (
<Grid>
<MaterialTable
title="Multiple Actions Preview"
columns={[
{ title: 'Name', field: 'name' },
{ title: 'Surname', field: 'surname' },
{ title: 'Birth Year', field: 'birthYear', type: 'numeric' },
]}
data={[
{ name: 'Mehmet', surname: 'Baran', birthYear: 2017 },
]}
/>
</Grid>
)
}
export default AdminTable
Can someone tell me why this is happening? Material table works fine when I use it outside this template but inside this template it does not align.
I am testing React FullCalendar for a project and I am having difficulties with the resources/rooms. Basically they are not appearing and I get this warning in the console Unknown option 'resources'
I have tried using json and js object but none of them seems to work.
You can also view it in codesandox here
Any help is appreciated
export default function App() {
const lunch = new Date();
const events = [
{
title: "Lunch",
start: lunch
}
];
const resources = [
{
id: "1",
title: "Room 1"
},
{
id: "2",
title: "Display room"
},
{
id: "3",
title: "MR-Fujita"
}
]
return (
<div className="App">
<FullCalendar
events={events}
resources={resources}
headerToolbar={{
left: "dayGridMonth,timeGridWeek,timeGridDay",
center: "title",
right: "prevYear,prev,next,nextYear"
}}
plugins={[dayGridPlugin, timeGridPlugin]}
initialView="timeGridWeek"
height="100%"
/>
</div>
);
}
You need to include resourceTimeGridPlugin plugin in your project via the calendar options, e.g:
plugins={[dayGridPlugin, timeGridPlugin, resourceTimeGridPlugin ]}
See the example at: https://fullcalendar.io/docs/vertical-resource-view
Bear in mind that this is a premium feature so you'd need a valid license.
This is a pretty generic error but in my case the difference is I installed this https://www.npmjs.com/package/react-native-dropdown-picker package and implementing it by first importing:
import DropDownPicker from 'react-native-dropdown-picker';
import Icon from 'react-native-vector-icons/Feather';
Then I'm creating the DopDownPicke as:
<DropDownPicker items={[
{ label: '1', value: 1 },
{ label: '2', value: 2 },
{ label: '3', value: 3 },
{ label: '4', value: 4 },
{ label: '5', value: 5 },
]} defaultValue={this.state.noOfIndToVac}
style={styles.dropDown}
itemStyle={{
justifyContent: 'flex-start'
}} dropDownStyle={{ backgroundColor: '#fafafa' }}
onChangeItem={item => this.setState({
noOfIndToVac: item.value
})} />
This is when I get the error
Unrecognized font family 'Feather'
I honestly don't care if I have the Feather font or not in the app, so is it possible to add a line of code that picks the system default font and stops showing this error?
It looks like you haven't finished setting up react native vector icons, because if you are successful, the feather icon should be included, check this official repository https://github.com/oblador/react-native-vector-icons
I'm new to AntD and having a little trouble with the stepper component - specifically, how to add a custom component into each of the steps.
For example,
const steps = [
{
title: 'First',
content: 'First-content',
},
{
title: 'Second',
content: 'Second-content',
},
{
title: 'Last',
content: 'Last-content',
},
];
For simplicity, if I were to use the Autocomplete component would it be just:
{
title: 'First',
content: '<Autocomplete />',
},
No luck so far. Any advice is appreciated.
There is no content in Steps.Step.
You may be trying to render a custom component in Steps, then you need to provide ReactNode and not a string type:
<Steps>
<Steps.Step> title="Finished" description={<AutoComplete/>} />
</Steps>
Its all mentioned in the docs, I believe what you need is the basics of React.
Maybe you found this official example Switch Step, there is a steps variable like this:
const steps = [
{
title: 'First',
content: 'First-content',
},
{
title: 'Second',
content: 'Second-content',
},
{
title: 'Last',
content: 'Last-content',
},
];
This is a user-defined variable, NOT pre-defined by antd, you can use whatever property even data structure you want. You can assign the ReactNode to content property like:
const steps = [
{
title: 'First',
content: <Autocomplete />,
},
// ...
]
And render the content based on current step state:
<div className="steps-content">{steps[current].content}</div>
There is NO content prop for the Steps.Step component. This is another way different from the accepted answer.
I really like what I've seen in antd so far, and I'm trying to introduce it to my current code base, but I can't seem to get a table to render, even when I just copy and paste examples into a new project. For example:
I ran create-react-app to get a fresh project, and updated the app component like so:
import React, { Component } from 'react'
import logo from './logo.svg'
import './App.css'
import {Table} from 'antd'
class App extends Component {
render() {
const columns = [{
title: 'Name',
dataIndex: 'name',
render: text => {text},
}, {
title: 'Age',
dataIndex: 'age',
}, {
title: 'Address',
dataIndex: 'address',
}]
const data = [{
key: '1',
name: 'John Brown',
age: 32,
address: 'New York No. 1 Lake Park',
}, {
key: '2',
name: 'Jim Green',
age: 42,
address: 'London No. 1 Lake Park',
}, {
key: '3',
name: 'Joe Black',
age: 32,
address: 'Sidney No. 1 Lake Park',
}, {
key: '4',
name: 'Disabled User',
age: 99,
address: 'Sidney No. 1 Lake Park',
}]
// rowSelection object indicates the need for row selection
const rowSelection = {
onChange: (selectedRowKeys, selectedRows) => {
console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows)
},
getCheckboxProps: record => ({
disabled: record.name === 'Disabled User', // Column configuration not to be checked
name: record.name,
}),
}
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<h1 className="App-title">Welcome to React</h1>
</header>
<p className="App-intro">
<Table>
columns={columns}
dataSource={data}
rowSelection={rowSelection}
</Table>
</p>
</div>
)
}
}
export default App
Note that the column, data, and rowSelection definitions were copied directly from the antd Table docs.
When the page attempts to render, I get the error "Objects are not valid as a React child"
I'm running React 16.2, but can't seem to find any version compatibility info in the antd docs so I'm not sure if that's an issue here.
Following the advice on the antd website, I used their sandbox template, and the table won't render there either. https://codesandbox.io/s/mml3lz31ox
If anyone can offer some insight here on how to use this table, I'd love to hear it!
The syntax is incorrect. It should be this:
<Table
columns={columns}
dataSource={data}
rowSelection={rowSelection}
/>
What your code is doing now is passing children instead, with columns=, dataSource= etc. being passed down as text, with {columns} and the like being interpreted as react element children. Objects are not valid there, hence the error.