I'm trying to figure out why my header and body rows aren't in sync. I'm using semantic ui for the css. Is it because my body rows are rendered in a different component? I tried moving them all to 1 and it didn't make any difference.
<table className="ui celled table" border="1">
<thead>
<tr>
<th >Status</th>
<th >Service Date of Visit</th>
<th >Claim ID</th>
<th >Insurance Plan</th>
</tr>
</thead>
<tbody>
{this.state.claims.map ( claim => <ClaimRow claim= { claim } /> ) }
</tbody>
and inside the component.
const ClaimRow = ( {claim} =this.props ) => (
<Form.Field>
<tr >
<td >
<input type="radio" name={claim._id} label="That Was Me" value="valid" checked={claim.status === 'valid'} />
Valid? <br />
<input type="radio" name={claim._id} label="Looks Like Fraud" value="fraud" checked={claim.status === 'fraud'} />
Fraud? <br />
<input type="radio" name={claim._id} label="Looks Like Fraud" value="notselected" checked={!claim.status && "defaultchecked"} />
Not Yet Sure
</td>
<td > {claim.claimDate} {claim.status}</td>
<td > {claim.claimID} </td>
<td > {claim.carrier} </td>
</tr>
</Form.Field>
);
ClaimRow.propTypes = {
claim: PropTypes.string.isRequired
};
export default
and the table footer
<tfoot className="full-width">
<tr>
<th colspan="4">
<div className="ui small button">
Approve
</div>
<div className="ui small button">
Approve All
</div>
<div className="ui right floated button" >
Next
<i class="right arrow icon"> </i>
</div>
<div className="ui right floated button" >
<i class="left arrow icon"></i>
Prev
</div>
</th>
</tr>
</tfoot>
</table>
Rows should be returning a <tr> at the top level, not a <Form.Field>.
for me adding this class worked.
.ReactTable .rt-tbody .rt-td{
margin-left: 0;
}
Related
I have a component, called Bucket, each bucket can have multiple challenges, it looks like this,
The code I have is like this, (much-simplified version)
class CLL_Bucket extends Component {
constructor(props) {
super(props);
this.state = {};
this.state = {
…
bucketChallengesIdx: 0, // to track the index of challegnes
bucketChallenges: this.props.bucket.bucketChallenges || [],
…
};
…
this.onBucketChallengeAdd = this.onBucketChallengeAdd.bind(this);
this.onBucketChallengeIDChanged = this.onBucketChallengeIDChanged.bind(this);
this.onBucketChallengeWeightChanged = this.onBucketChallengeWeightChanged.bind(this);
}
render() {
const bucketIdx = this.props.idx;
return (
<div style={styles.container}>
<div key={bucketIdx} className="row" style={styles.bucketStyle}>
<div className="col-md-2">
…
</div>
<div key={bucketIdx} className="col-md-4">
<div>
<label>
<span className="text-center">Challenges<span>
</label>
<button type="button" className="btn btn-success btn-sm" onClick={() => this.onBucketChallengeAdd()}>Add Challenge</button>
</div>
<table className="table table-bordered table-striped show">
<thead>
<tr>
<th>Challenge ID</th>
<th>Weight</th>
<th>Action</th>
</tr>
</thead>
<tbody>
{this.state.bucketChallenges.map(this.renderBucketChallenges.bind(this))}
</tbody>
</table>
</div>
…
</div>
</div>
);
}
renderBucketChallenges(bucketIdx, idx){
return (
<tr key={idx}>
<td className="col-xs-3 input-group-sm">
<Select
options={challengeIDOptions}
defaultValue={challengeIDOptions[0]}
onChange={this.onBucketChallengeIDChanged.bind(this, idx)}
value={this.state.bucketChallengesID}
isSearchable={true}
/>
</td>
<td className="col-xs-1 input-group-sm">
<input type="text" className="form-control" value={this.state.bucketChallengesWeight}
onChange={(e) => this.onBucketChallengeWeightChanged(idx, e)} disabled={this.props.readOnly}>
</input>
</td>
<td className="col-xs-1 input-group-sm">
…
</td>
<td className="col-xs-1 input-group-sm">
<input className="btn btn-danger btn-sm" id="deleteButton" type="button" value="Delete" onClick={() => this.onDeleteChallenge.bind(this, bucketIdx, idx)} />
</td>
</tr>
);
}
onBucketChallengeAdd(){
var newChallengeIndex = this.state.bucketChallengesIdx + 1;
console.log("onBucketChallengeAdd(): " + newChallengeIndex);
this.setState({bucketChallengesIdx: newChallengeIndex});
this.props.onAddChallenge(this.props.idx, newChallengeIndex);
}
The problem I’m having is, when I click the “Add Challenge” button, I can see from the React developer tool that a new challenge is being added, even though the UI is not updated. When I go to a different tab of my app and come back, the UI is added (a new row for the added challenge is there). Why? Any suggestion on how to fix this? Thanks!
The bigger question is, am I on the right track to make this happen? or i should extract challenge portion to a different component?
I have a table whose items I render through a list. The idea is that, on clicking the name of a row, a modal will open and that will print certain values retrieved from the backend server.
Initially, for the modal, my data-target was the ID of my modal. After looking at this answer I realised that I might be doing something wrong and changed that data-target to the ID of the row. Now the problem is that the modal is not opening at all.
Edit: I realised I was doing something wrong when ID of my modal was fixed because irrespective of whichever name I clicked, the same information was loading. Through console.log I could see that the right values were being passed but only was being displayed.
What am I doing wrong here?
The rendered code for the table is as follows:-
<table className="table">
<thead>
<tr>
<th>S. NO.</th>
<th>NAME</th>
<th>ADDRESS</th>
<th>TELEPHONE</th>
<th>EMAIL</th>
<th>AGE</th>
<th></th>
</tr>
</thead>
<tbody>
{this.state.personData.map((pRow, idx) => (
<>
<PersonModal id={pRow.id} />
<tr key={pRow.id}>
<td>{idx + 1}</td>
<td data-toggle="modal" data-target={pRow.id}>{pRow.name}</td>
<td>{pRow.address}</td>
<td>{pRow.phone}</td>
<td>{pRow.email}</td>
<td>{pRow.age}</td>
<td>
{" "}
<DeleteButton id={pRow.id} onDelete={this.onDelete} />{" "}
</td>
</tr>
</>
</tbody>
</table>
This is the rendered code for the modal:-
render() {
console.log("Component rendered");
return (
<React.Fragment>
<div className="modal" id={this.props.id}>
<div className="modal-dialog">
<div className="modal-content">
<div className="modal-body">
{this.props.id}
</div>
<div className="modal-footer">
<button type="button" className="btn optionsButton" data-dismiss="modal">CLOSE</button>
</div>
</div>
</div>
</div>
</React.Fragment>
);
}
I am trying to create a dropdown/collapse area within a table row that is the full width of the table with Bootstrap 4 and React JS. I haven't been able to find a visual of what I want, I just remember using it somewhere before (maybe on AWS?), but I haven't been able to locate it again.
EDIT: Desired action has been found (https://i.imgur.com/Pcg1JgI.png). Once the chevron is clicked, the below rows open.
This is my current code:
import React from "react";
import { API, graphqlOperation } from 'aws-amplify';
import { listTrackerItems } from '../graphql/queries';
class TrackerGeneralPage extends React.Component {
state = {
id: '',
active: [],
completed: [],
completedDateNow: '',
newStatus: 'Complete'
};
async componentDidMount() {
const result = await API.graphql(graphqlOperation(listTrackerItems))
let data = result.data.listTrackerItems.items
let General = data.filter(t=>t.department === 'General');
const activeGeneral = General.filter(t=>t.status === 'Active');
const completedGeneral = General.filter(t=>t.status === 'Completed');
const date = new Date();
const month = date.getUTCMonth() + 1;
const day = date.getUTCDate();
const year = date.getUTCFullYear();
const timeNow = month + "/" + day + "/" + year;
this.setState({active: activeGeneral, completed: completedGeneral, completedDateNow: timeNow });
}
render() {
const { active } = this.state
return (
<>
<div>
<div class="container">
<div class="row">
<div class="col-sm">
</div>
<div class="col-sm">
<div className="mx-auto" align="center">
<h1>General</h1>
</div>
</div>
<div class="col-sm">
<div className="mx-auto mt-2" align="center">
{/* <!-- Button trigger modal --> */}
<a role="button" className="btn btn-dark" href="/tracker/nwa/lab/add" >
Add Tracker
</a>
</div>
</div>
</div>
</div>
{/* Active Trackers */}
<div id="toggle-active" className="">
<div className="my-4">
<table className="table table-hover table-bordered mb-3">
<thead className="thead-dark">
<tr>
<th scope="col">Actions</th>
<th scope="col">Name</th>
<th scope="col">Regulation</th>
{/* <th scope="col">Occurrence</th> */}
<th scope="col">Due On</th>
<th scope="col">Assigned</th>
<th scope="col">Status</th>
{/* <th scope="col">Completer</th>
<th scope="col">Date Completed</th>
<th scope="col">Description</th> */}
</tr>
</thead>
<tbody>
{active.map(item => (
<tr key={item.id}>
<th scope="row" className="dropdown">
<a class="btn" data-toggle="collapse" href="#collapseExample" role="button" aria-expanded="false" aria-controls="collapseExample"><img src="https://icon.now.sh/chevronDown" width="25" height="25" className="d-inline-block align-top" alt="Open Row" /></a>
</th>
<td>{item.name}</td>
<td>{item.reg}</td>
<td>{item.dateDue}</td>
<td>{item.assigned}</td>
<td>{item.status}</td>
<div class="collapse" id="collapseExample">
<div class="card card-body">
<td>{item.occurrence}</td>
<td>{item.completer}</td> */}
<td>{item.dateCompleted}</td>
<td>{item.description}</td>
</div>
</div>
</tr>
))}
</tbody>
</table>
</div> {/* End Table Section */}
</div> {/* End Active Toggle */}
</div> {/* End Container */}
</>
)
}
}
export default TrackerGeneralPage;
If I currently click the dropdown arrow, it places it to the right side of the table: visual on imgur.
If I move this:
<div class="collapse" id="collapseExample">
<div class="card card-body">
<td>{item.occurrence}</td>
<td>{item.completer}</td> */}
<td>{item.dateCompleted}</td>
<td>{item.description}</td>
</div>
</div>
into the <th> where the dropdown/collapse button is located, it places it all into that specific column only: visual on imgur.
I would like the button to open the dropdown/collapse area directly under the table row, as if its attached, (pushing the row beneath further down) and be full width of the table/row.
Each button would need to only open that specific rows dropdown/collapse area as well, and right now if I click any button, it opens all of the rows dropdown/collapse areas.
How is this accomplished/what is this called?
Take this as an idea. Simply add collapse to your <td> and overwrite bootstrap <td> padding;
You can pass value to replace the data-target with unique id for each row like fd1, fd2or other id name that can avoid collision via your map function.
/*overwrite bootstrap table padding*/
.hiddenRow {
padding: 0 !important;
}
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<table class="table table-hover">
<thead>
<th></th><th>1</th><th>2</th><th>3</th>
</thead>
<tbody>
<tr data-toggle="collapse" data-target="#folder1">
<td class="text-center"><span>+</span></td>
<td>Cell 1.1</td>
<td>Cell 1.2</td>
<td>Cell 1.3</td>
</tr>
<tr>
<td colspan="4" class="hiddenRow">
<div id='folder1' class="collapse">
row1
</div>
</td>
</tr>
<tr data-toggle="collapse" data-target="#folder2">
<td class="text-center"><span>+</span></td>
<td>Cell 2.1</td>
<td>Cell 2.2</td>
<td>Cell 2.3</td>
</tr>
<tr style="background:lightyellow">
<td colspan="4" class="hiddenRow">
<div id="folder2" class="collapse">
row2
</div>
</td>
</tr>
</tbody>
</table>
I'm using the following code to generate a simple UI, and I'm trying to convert it to use Bootstrap.
This is my original code (using Skeleton);
render:function(){
return (
<div className="grocery-item row">
<div className="six columns">
<h4 className={this.props.item.purchased ? "strikethrough" : "" }>
{this.props.item.name}
</h4>
</div>
<form onSubmit={this.togglePurchased} className="three columns">
<button className={this.props.item.purchased ? "btn btn-danger" : "button-primary"}>{this.props.item.purchased ? "unbuy" : "buy"}</button>
</form>
<form className="three columns" onSubmit={this.delete}>
<button>×</button>
</form>
</div>
)
}
I tried doing something like this;
render:function(){
return (
<table class="table table-striped">
<thead>
<tr>
<th>Column 1</th>
<th>Columan 2</th>
<th>Columan 3</th>
</tr>
</thead>
<tbody>
<tr>
<h4 className={this.props.item.purchased ? "strikethrough" : "" }>{this.props.item.name}</h4>
<form onSubmit={this.togglePurchased} className="three columns">
<button className={this.props.item.purchased ? "btn btn-danger" : "button-primary"}>{this.props.item.purchased ? "unbuy" : "buy"}</button>
</form>
<form className="three columns" onSubmit={this.delete}>
<button>×</button>
</form>
</tr>
</tbody>
</table>
)
}
But it's not working like I expect. I'm using react-express-examplar as my starting point.
How can I get Bootstrap tables working in my React app?
I think you'll have an easier time if you start your app using create-react-app. They even give instructions on how to use Bootstrap with React.
You said you're new to React. There are a lot of moving parts that can be overwhelming to figure out at first. Using create-react-app will take out a lot of the learning curve and make it a lot easier for you to get started with as little friction as possible.
Good luck!
From my understanding, you want the name and buy/unbuy buttons to come as a row , under respective columns.
In the tr tag, give each html part as a td tag
Please refer below html snippet:
<td>
<h4 class="strikethrough">
name
</h4>
</td>
<td>
<form class="three columns">
<button class="btn btn-info">buy</button>
</form>
</td>
<td>
<form class="three columns">
<button>×</button>
</form>
</td>
Please try to modify the html in your component render method, similarly.
You added table to wrong Component. It must be on GroceryItemList.jsx
Caution: Form is not allowed inside table. I'm just providing the structure and UI and code is not tested.
::: structure should something like-
GroceryItemList.jsx Component::::
render:function(){
return (
<div>
<table className="table">
<thead>
<tr>
<th>Column 1</th>
<th>Columan 2</th>
<th>Columan 3</th>
</tr>
</thead>
<tbody>
{this.props.items.map((item,index)=>{
return (
<GroceryItem item={item} key={"item"+index} />
)
})}
<GroceryListAddItem />
</tbody>
</table>
</div>
)
}
GroceryItem.jsx Component::::
render:function(){
return (
<tr>
<td>
<h4 className={this.props.item.purchased ? "strikethrough" : "" }>
{this.props.item.name}
</h4>
</td>
<td>
<form onSubmit={this.togglePurchased}>
<button className={this.props.item.purchased ? "" : "button-primary"}>{this.props.item.purchased ? "unbuy" : "buy"}</button>
</form>
</td>
<td>
<form onSubmit={this.delete}>
<button>×</button>
</form>
</td>
</tr>
)
}
i'm developing for the first time with Angular JS and i created the following bootstrap modal in which there is a table with some content and inputs. Here is the code:
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4>User Menu</h4>
</div>
<div class="modal-body">
<div class="tablecontainer">
<table class="table table-striped table-hover table-condensed">
<colgroup>
<col class="col-md-1">
<col class="col-md-2">
<col class="col-md-2">
<col class="col-md-3">
<col class="col-md-2">
<col class="col-md-2">
</colgroup>
<thead>
<tr>
<th> </th>
<th>Firstname</th>
<th>Lastname</th>
<th>Address</th>
<th>Attachment</th>
<th>Group</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="user in users">
<td>
<input type="checkbox" value="" ng-model="ctrl.checked[$index]" ng-disabled="ctrl.fileupload!==undefined" ng-change="ctrl.checkBox($index)" />
</td>
<td>{{user.firstname}}</td>
<td>
<select class="form-control" ng-model="user.selectedAddress" ng-change="ctrl.checked[$index] = user.selectedAddress.destAddress" ng-options="o as o.destName for o in user.addresses"></select>
</td>
<td>{{user.selectedAddress.destAddress}}</td>
<td><input type = "text" class="customPart"
ng-model="ctrl.customText[$index]" /></td>
</tr>
</tbody>
</table>
</div>
[...]
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default btn-flat" data-dismiss="modal">Close</button>
</div>
</div>
</div>
What is the angular way of clearing bootstrap modal to reset the user inputs?
You don't reset the UI to have a fresh model, you wan't to do the contrary. You need to reset the model, then your UI will be reset.
You can write a function that will reset your users array. For example:
function reset() {
for(var i = 0; i < users.length; i++) {
users[i].selectedAddress = null;
}
}