i am mapping values on the table, i want the table to have scrollbar when it reaches some max-height,
adding overflow: scrollbar, width max-height: 600px did not work, the table just keeps extending downwards
return (
<div className='journaltable-div'>
<table className='table table-journal'>
<thead className='table-head'>
<tr className='table-head-row'>
<th>Task</th>
<th>Date-created</th>
<th>Action</th>
</tr>
</thead>
<tbody className='table-body'>
{ journalList.map((entry) => {
const { key, journal, time } = entry
return (
<tr key={key} className="table-body-row">
<td>{journal}</td>
<td>{time}</td>
<td><button
className='button button-complete'
onClick={(e) => {
e.stopPropagation
addToLog(key, "completed")
removeJournal(key)
}}>completed</button><button
className='button button-delete'
onClick={(e) => {
e.stopPropagation
addToLog(key, "deleted")
removeJournal(key)
}}>delete</button></td>
</tr>
)
}) }
</tbody>
</table>
<div className='redirect-div'>
<button className='redirect-logs' style={{cursor: 'pointer'}} onClick={() => {handleLogs()}}> Check Logs</button>
</div>
</div>
.table-journal {
overflow: scroll;
max-height: 600px;
}
also tried placing on tbody did not work either
put all of your return values from the map function in a div with scrollit style class and add these codes to your CSS:
.scrollit {
overflow:scroll;
height:100px;
}
your code have look like this:
return (
<div className='journaltable-div'>
<table className='table table-journal'>
<thead className='table-head'>
<tr className='table-head-row'>
<th>Task</th>
<th>Date-created</th>
<th>Action</th>
</tr>
</thead>
<tbody className='table-body'>
<div className="scrollit">
{ journalList.map((entry) => {
const { key, journal, time } = entry
return (
<tr key={key} className="table-body-row">
<td>{journal}</td>
<td>{time}</td>
<td><button
className='button button-complete'
onClick={(e) => {
e.stopPropagation
addToLog(key, "completed")
removeJournal(key)
}}>completed</button><button
className='button button-delete'
onClick={(e) => {
e.stopPropagation
addToLog(key, "deleted")
removeJournal(key)
}}>delete</button></td>
</tr>
)
}) }
</div>
</tbody>
</table>
<div className='redirect-div'>
<button className='redirect-logs' style={{cursor: 'pointer'}} onClick={() => {handleLogs()}}> Check Logs</button>
</div>
</div>
Related
My elements seems to transition or "fly" in from the top of my page. This is not what I want as I want them to transition from the row to which they belong. How can I achieve this behaviour?
Vue template looks like this.
<li class="accordion-parent" v-for="(parent, pIndex) in list" :key="pIndex">
<div class="accordion-entry">
<div
#click="() => toggleExpand(pIndex)"
:class="[{ expanded: expanded === pIndex }, outerDiv]"
>
<table class="accordion-expanded">
<transition-group name="fade" tag="v-layout" class="manual-v-layout">
<tbody
v-for="index in 10"
:key="index"
class="cycle"
v-show="expanded === pIndex"
>
<tr class="view-more-row" v-show="expanded === pIndex">
<td />
<td class="view-more-cell">
<span> View more cycles </span>
</td>
</tr>
</tbody>
<tbody key="id">
<transition name="fade">
<tr class="view-more-row" v-show="expanded === pIndex">
<td />
<td class="view-more-cell">
<span> View more cycles </span>
</td>
</tr>
</transition>
</tbody>
</transition-group>
</table>
</div>
</li>
Vue script
<script>
export default {
name: "AnalyticsAccordion",
data() { return { list: [1,2,3,4] }
},};
</script>
Css
<style>
tbody {
transition: 0.5s;
width: 100%;
}
.manual-v-layout {
display: flex;
flex-wrap: wrap;
flex-direction: row;
}
</style>
When the button active is clicked it is replaced by deactive button and vice versa this is going all good in size greater than 768px but when the screen size is smaller than 768px the button active is not replaced by deactive button rather the two-button appears at a different position in toggling on the small screen
I think changes should be in display property when the screen is <=768px that it adjust it in a way that in toggling the button replaces each other in exactly the same position as it is working on big screen.
My code:
document.querySelectorAll('.activeBtn').forEach(btn => {
btn.addEventListener('click', function(e) {
e.preventDefault();
this.closest('tr').classList.remove('active');
});
});
document.querySelectorAll('.deactiveBtn').forEach(btn => {
btn.addEventListener('click', function(e) {
e.preventDefault();
this.closest('tr').classList.add('active');
});
});
tr a.activeBtn {
display: none;
}
tr a.deactiveBtn {
display: inline;
}
tr.active a.activeBtn {
display: inline;
}
tr.active a.deactiveBtn {
display: none;
}
<div class="detailsCategory">
<div class="recentCategory">
<div class="card-header">
<h2>Categories </h2>
Add Categories
</div>
<table>
<thead>
<tr>
<td class="serial">#</td>
<td>ID</td>
<td>Categories</td>
<td></td>
</tr>
</thead>
<tbody>
<tr class="active">
<td class="serial">1</td>
<td>4202211</td>
<td>Men</td>
<td class="statusButtons">
<span><a href="#" class='status activeBtn' >Active</a></span>
<span><a href="#" class='status deactiveBtn'>Deactive</a></span>
<span><a href="#" class='status editBtn'>Edit</a></span>
<span><a href="#" class='status deleteBtn'>Delete</a></span>
</td>
</tr>
</tbody>
</table>
</div>
</div>
You have protected spaces after each span and therefor the line isn't empty and therefor isn't hidden. To prevent the issue you have to omit these. You could instead define a margin for the spans:
.statusButtons span {
margin-right: 3px;
}
Working example:
document.querySelectorAll('.activeBtn').forEach(btn => {
btn.addEventListener('click', function(e) {
e.preventDefault();
this.closest('tr').classList.remove('active');
});
});
document.querySelectorAll('.deactiveBtn').forEach(btn => {
btn.addEventListener('click', function(e) {
e.preventDefault();
this.closest('tr').classList.add('active');
});
});
tr a.activeBtn {
display: none;
}
tr a.deactiveBtn {
display: inline;
}
tr.active a.activeBtn {
display: inline;
}
tr.active a.deactiveBtn {
display: none;
}
.statusButtons span {
margin-right: 3px;
}
<div class="detailsCategory">
<div class="recentCategory">
<div class="card-header">
<h2>Categories </h2>
Add Categories
</div>
<table>
<thead>
<tr>
<td class="serial">#</td>
<td>ID</td>
<td>Categories</td>
<td></td>
</tr>
</thead>
<tbody>
<tr class="active">
<td class="serial">1</td>
<td>4202211</td>
<td>Men</td>
<td class="statusButtons">
<span><a href="#" class='status activeBtn' >Active</a></span>
<span><a href="#" class='status deactiveBtn'>Deactive</a></span>
<span><a href="#" class='status editBtn'>Edit</a></span>
<span><a href="#" class='status deleteBtn'>Delete</a></span>
</td>
</tr>
</tbody>
</table>
</div>
</div>
I am trying to list options on my page from top to bottom rather than left to right.
return (
<div className="quizChallenge">
<WebHeader/>
<h2 id = "description"> {this.state.quizzes.description}</h2>
<ol>
<table id="t01">
<tbody>
<tr>
{this.state.options.map((option) => {
return (
<td key={option}>
<button disabled={!this.state.optionEnabled} onClick={() => this.checkAnswer(this.state.options.indexOf(option))}>
{option}
</button></td>
);
})}
</tr>
</tbody>
</table>
</ol>
{currentQuestion < 8 &&
<button className="ui inverted button" disabled={this.state.disabled} onClick={this.nextQuestion}>Next</button>
}
{currentQuestion === 7 &&
<button className="ui inverted button" disabled={this.state.disabled} onClick={this.lastQuestion}>Finish Quiz!</button>
}
</div>
);
Can someone assist me with the best way of doing this?
Change this:
<tr>
{this.state.options.map((option) => {
return (
<td key={option}>
<button disabled={!this.state.optionEnabled} onClick={() => this.checkAnswer(this.state.options.indexOf(option))}>
{option}
</button></td>
);
})}
</tr>
to
{this.state.options.map((option) => {
return (
<tr>
<td key={option}>
<button disabled={!this.state.optionEnabled} onClick={() => this.checkAnswer(this.state.options.indexOf(option))}>
{option}
</button>
</td>
<tr>
);
})}
Explanation by Woodrow Barlow: tr stands for "table row" and td for "table data". with multiple data cells in a single row, they display horizontally. With one data cell per row, they display vertically.
I want to have a table with horizontal and vertical scrollbar .
showcase in primeNg work properly when we don't use rtl direction for our table !
when we use horizontal scroll and rtl direction scroll doesn't scroll on table header ! table header is fixed when we use in rtl dir
mycode:
<div dir="rtl">
<p-table dir="rtl" #dt
[columns]="cols"
[value]="cars"
[paginator]="true"
[rows]="10"
[scrollable]="true"
scrollHeight="200px"
[style]="{width:'1000px'}">
<!-- below for fixining columns withs-->
<ng-template pTemplate="colgroup" let-columns>
<colgroup>
<col *ngFor="let col of columns" style="width:150px;">
</colgroup>
</ng-template>
<ng-template pTemplate="header" let-columns>
<tr dir="rtl" class="ui-rtl">
<th *ngFor="let col of columns">
{{col.header}}
</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-rowData let-columns="columns">
<tr [pSelectableRow]="rowData">
<td *ngFor="let col of columns">
{{rowData[col.field]}}
</td>
</tr>
</ng-template>
</p-table>
</div>
PrimeNG doesn't support RTL for table component.
So workaround would be to listen for scroll event on the body and assign the same exact shift to the header:
scrollableTableBodyScroll: () => void;
constructor(
private el: ElementRef,
private zone: NgZone,
) { }
ngAfterViewInit(): void {
const scrollableTableHeader: HTMLElement = this.el.nativeElement.querySelector('.ui-table-scrollable-header');
const scrollableTableBody: HTMLElement = this.el.nativeElement.querySelector('.ui-table-scrollable-body');
this.zone.runOutsideAngular(() => {
this.scrollableTableBodyScroll = this.renderer.listen(scrollableTableBody, 'scroll', () => {
scrollableTableHeader.scrollLeft = scrollableTableBody.scrollLeft;
});
});
}
ngOnDestroy(): void {
this.scrollableTableBodyScroll();
}
Reasons behind use of NgZone
I have a bootstrap table which is populated by an MVC loop of a model. However when my model renders a large number of records, it causes the table and panel the table is nested in stretch out too much in height. Is there a recommended way of making the table result scrollable when the records returned would exceed the max-height property of the table? A scrollable solution would be optimal.
Styles
.table{
width:100%;
}
thead,tbody,tr,td,th{
display:grid;
}
tr:after{
content: ' ';
display: block;
visibility:hidden;
clear:both;
}
thead th{
height: 30px;
}
tbody {
height: 120px;
overflow-y:auto;
}
thead {
}
tbody td. thead th {
width: 40.2%;
float: left;
}
Code below: (loop displays 34 records)
<div class="panel panel-primary">
<div class="panel-heading clearfix">
<h4 class="panel-title pull-left" style="padding-top: 7.5px;">My Team</h4>
<div class="btn-group pull-right">
<!--- Search bar-->
<form class="navbar-form navbar-right" role="search">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search My Team">
<span class="input-group-btn">
<button type="submit" class="btn btn-default">
<span class="glyphicon glyphicon-search"></span>
</button>
</span>
</div>
</form>
</div>
</div>
<table class="table table-responsive table-hover" style="max-height:150px; height:100px;">
<thead>
<tr>
<th>#Html.DisplayNameFor(model => model.Name)</th>
<th>LAN ID</th>
<th>Department</th>
<th>Email</th>
</tr>
</thead>
<tbody>
#foreach(var x in Model)
{
<tr class="info">
<td>
#Html.DisplayFor(modelItem => x.Name)
</td>
<td>
#Html.DisplayFor(modelItem => x.Lan_Id)
</td>
<td>
#Html.DisplayFor(modelItem => x.CurrDept)
</td>
<td>
#Html.DisplayFor(modelItem => x.Email)
</td>
</tr>
}
</tbody>
</table>
<div class="panel-footer"></div>
make a table structure as follows. Should resolve your issue
<div class="table-responsive">
<table class="table table-striped table-bordered">
//rest of code
</table>
</div>