Table styles not working properly - react-virtualized

I've been doing some research on this subject, and I've worked with both the Grid, List, and MultiGrid now with react-virtualized and have gotten those to work properly. I've been running into some issues with the table again though. I can't seem to get the table columns to render properly despite following all of the instructions and the docs, though I haven't been able to get it to work properly, any help would be much appreciated.
import React, { Component } from 'react';
import 'react-virtualized/styles.css';
import {Table, Column, AutoSizer} from 'react-virtualized';
const data = [
{rsid:'10001',gene:'BRCA1',chr_position:'1000000',allele:'C'},
{rsid:'10011',gene:'BRCA1',chr_position:'1000001',allele:'D'},
{rsid:'10021',gene:'BRCA1',chr_position:'1000002',allele:'C'},
{rsid:'10031',gene:'BRCA1',chr_position:'1000003',allele:'C'},
];
class ExpectoSnpTable extends Component{
constructor(props){
super(props);
}
render() {
return(
<div>
<Table
height={500}
rowGetter={({index}) => data[index]}
rowCount={data.length}
rowHeight={40}
width={500}
headerHeight={20}
>
<Column
dataKey='rsid'
width={100}
headerRenderer={({dataKey})=> 'rsid'}
/>
<Column
dataKey='gene'
width={100}
headerRenderer={({dataKey})=> 'gene'}
/>
<Column
dataKey='chr_position'
width={200}
headerRenderer={({dataKey})=> 'chr_position'}
/>
<Column
dataKey='allele'
width={100}
headerRenderer={({dataKey})=> 'allele'}
/>
</Table>
</div>
);
}
}
export default ExpectoSnpTable;
Example

Related

Is there a way to use a Modal in a React Class Component

I am trying to render a single draft once I click the modal, instead of navigating to the other component... if that makes sense... im getting to display it but then it redirects me because of the Link.. but if i dont add the Link then I loose my draftId on url
This is part of my code
class Drafts extends React.Component {
componentDidMount() {
this.props.fetchAllDrafts()
}
render() {
const drafts = this.props.drafts
return (
<React.Fragment>
<Table aria-label="a dense table" className="myaccount-table">
<TableHead>
<TableRow>
<TableCell align="center">
<div className="date-content">Date</div>
</TableCell>
<TableCell align="center">Content</TableCell>
<TableCell> </TableCell>
<TableCell> </TableCell>
</TableRow>
</TableHead>
<TableBody>
{drafts.map((draft) => (
<TableRow key={draft.id}>
<TableCell>
<div className="datecontent">{draft.createdAt}</div>
</TableCell>
<TableCell>
<div className="content">{draft.content} </div>
</TableCell>
<TableCell>
<Link to={`/drafts/${draft.id}`}>
<Popup
trigger={<button className="button"> Read </button>}
modal
nested
>
<SingleDraft />
{/* <Button color="primary">
Read
</Button> */}
</Popup>
</Link>
the is comming from another class component
class SingleDraft extends React.Component {
constructor() {
super()
}
componentDidMount() {
this.props.fetchDraft(this.props.match.params.draftId)
}
render() {
return (
<div>
<p>{this.props.singleDraft.content} </p>
<Link to={`/texteditor/${this.props.singleDraft.id}`}>
<button>Update</button>
</Link>
</div>
)
}
Why don't you pass the draftId as a prop?
<Popup
trigger={<button className="button"> Read </button>}
modal
nested
>
<SingleDraft draftId={draft.id} />
{/* <Button color="primary">Read</Button> */}
</Popup>
And in your component.
componentDidMount() {
this.props.fetchDraft(this.props.draftId)
}

Iterate through array and display React component one at a time

I have the following page:
const GalleryPage: NextPage = () => {
const router = useRouter();
const id = router.query.id as string;
return (
<Gallery id={id} imageUrl="someRandomImageUrl.png" />
);
};
And within the Gallery Component, I have
...
return (
<div>
<Form
onSubmit={handleSubmit}
name="judging"
>
<input type="hidden" name="form-name" value="judging" />
<Container text style={{ marginTop: '2em' }} textAlign="center">
<Image src={galleryProps?.imageUrl} size="medium" verticalAlign="middle" />
<Table singleLine>
<Table.Header>
<TableHeader />
</Table.Header>
<Table.Body>
<TableRow
title="Composition"
name="composition"
item={composition}
setItem={setComposition}
/>
<TableRow
title="Creativity - Originality"
name="creativity"
item={creativity}
setItem={setCreativity}
/>
<TableRow
title="Neatness - Finishing details"
name="neatness"
item={neatness}
setItem={setNeatness}
/>
</Table.Body>
</Table>
</Container>
<Container text style={{ marginTop: '1em' }} textAlign="center">
<p>
<Button type="submit">Submit</Button>
</p>
</Container>
</Form>
</div>
);
Where TableRow and TableHeader are custom components.
What I can't seem to make happen
I have an array of image URLs:
const imageUrls = ['firstImageUrl.png', 'secondImageUrl.jpeg', 'thirdImageUrl.png']
And for each item in the imageUrls, I want to display the Gallery component. And only once the form in the Gallery is submitted, do I want the next instance to display with the following image.
ie:
firstcase: <Gallery id={id} imageUrl="firstImageUrl.png" /> once form submitted, second case
secondcase: <Gallery id={id} imageUrl="secondImageUrl.jpeg" /> once form submitted, third case ...
You can create a state called galleryIndex that starts of as 0 and then to gallery you pass a function prop called onSumbit and inside there you increase the state galleryIndex by 1 and then inside the Gallery page you set imageUrl on Gallery component to be the element from the array imageUrls at the index galleryIndex

How do I have more complex layouts in `react-admin` "Show" and "Edit" and "Create" screens?

I'm trying to build on react-admin. The base structure is this:
<Show {...props} >
<SimpleShowLayout>
<TextField source="id" />
<TextField source="name" />
</SimpleShowLayout>
</Show>
I'm looking to do something like this:
<Show {...props} >
<div className="row">
<div className="col-sm-6">
<TextField source="id" />
</div>
<div className="col-sm-6">
<TextField source="name" />
</div>
</div>
</Show>
We need to update our documentation about this. We recently decoupled components with logic, that we name XXXController (ListController, CreateController, etc) in the ra-core package and UI components (List, Create, etc) in the ra-ui-materialui package which the controllers.
Think about the react-admin package as a distribution of react-admin with material-ui UI. When heavy customization is needed, you can use the controllers directly.
For now, you'll have to explore the source code to fully understand how to use them.
Here's an example:
import { ShowController, ShowView, SimpleShowLayout, TextField } from 'react-admin';
const UserShow = props => (
<ShowController {...props}>
{controllerProps =>
// You're on your own here
}
</ShowController>
);

Material UI - Checkbox Label is Missing

I'm learning Material UI and I'm trying to display an checkbox with a label. Following the samples in the online docs, I'm rendering a checkbox, but no label. What am I doing wrong?
return (
<div className="entryForm" >
<div style={{width:'100%'}}>
<h3 style={ {display:'inline-block' } }>
User Details
</h3>
<span style={{float:'right'}}>
<Checkbox
label="Active"
labelPosition="left"
/>
</span>
</div>...
I think it depends on the MUI version you are using.
If you're using version 1.0 and above you should use FormControlLabel:
import {FormControlLabel} from 'material-ui/Form';
<FormControlLabel
control={
<Checkbox
name="SomeName"
value="SomeValue"
/>
}
label="MyLabel"/>
More in the documentation:
https://material-ui-next.com/demos/selection-controls/
FormControlLabel would be the way to go, here is what it looks like with the updated import v4.11.1
import { FormControlLabel } from '#material-ui/core';
<FormControlLabel
control={
<Checkbox
name="SomeName"
value="SomeValue"
/>
}
label="MyLabel"/>

ReactJs using CSS per page

I'm using ReactJs to build a simple app with 3 routes:
"/" <- index.js
"/login" <- login.js
"/register" <- register.js
to view these pages correctly, i need to import CSS-files.
But if i import the CSS-file for the "/login" route, it also gets loaded in the "/" route.
here are my files:
app.js
import React, { Component } from 'react';
import { BrowserRouter as Router, Switch, Route, Link } from 'react-router-dom';
import './App.css';
import Index from './pages/index';
import Login from './pages/login';
import './css/bootstrap.css';
class App extends Component {
render() {
return (
<Router>
<Switch>
<Route exact path='/' component={Index} />
<Route exact path='/login' component={Login} />
</Switch>
</Router>
);
}
}
export default App;
index.js
import React, { Component } from 'react';
import { Link } from 'react-router-dom';
import logo from '../logo.svg';
import '../App.css';
class Index extends Component {
render() {
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">
To get started, edit <code>src/App.js</code> and save to reload.
<Link to={'/login'}>Login</Link>
</p>
</div>
);
}
}
export default Index;
and login.js
import React, { Component } from 'react';
import { Link } from 'react-router-dom';
import '../css/login.css';
import '../css/main.css';
import logo from '../img/s900x300.png';
import back from '../img/back.svg';
import view from '../img/view.svg';
export default class Login extends Component {
render() {
return (
<div>
<script async="" src="https://www.google-analytics.com/analytics.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<button className="back">
<a><img alt="" className="left" src={back}/></a>
</button>
<div className="background">
</div>
<div id="login" className="container login">
<img alt="" src={logo} />
<center><h5>‌</h5></center>
<input name="user" type="text" required placeholder="Benutzername oder Email"/>
<div className="password">
<input name="pw" required maxLength="64" type="password" placeholder="Passwort"/>
<button id="view_toggle">
<img alt="" src={view}/>
</button></div>
<form>
<button id="login" className="on">Login</button>
</form>
<center><b><a>back</a> | <Link to={'/register'}><a>Create account</a></Link></b></center>
</div>
<script src="/js/bootstrap.min.js"></script>
</div>
);
}
}
for example: in my login.css want a background image for my body. but this background is also applied to "/". How can i prevent, that the css is used global? Sorry for my bad english :)
To avoid your issue, you can create a global css file like style.css
then you link it to your index.html
as #Chase DeAnda suggest you can establish namespace for each page.
your style.css should be something like
.login .myClass {...}
.login .anotherClass {...}
.main .myClass {...}
.main .anotherClass {...}

Resources