Listing elements from top to bottom rather than horizontally - css

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.

Related

how to I add a scrollbar for the table

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>

How to avoid elements transitioning from top of page with transition

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>

scrollable and rtl doesn't work in primeNG table

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

how can my modal know index in row clicked reactjs

I am a beginner in this language I've used php before.
So the table has a button and when I clicked the button it only read the first row it won't read the other rows, In php ive used the function attr so it will read the other clicked row and here at reactjs i don't know how please help
return <tr key={i} >
<td>{d.Employee_Name}</td>
<td>{d.Address}</td>
<td><center><button className ="btn btn-info" onClick={ this.props.onClick } data-toggle="modal" data-target="#UpdateEmployee">Update</button></center></td>
<td><center><button className ="btn btn-danger">Delete</button></center></td>
<div className="modal fade" id="UpdateEmployee" role="dialog">
<div className="modal-dialog">
<div className="modal-content">
<div className="modal-header">
<button type="button" className="close" data-dismiss="modal">×</button>
<h4 className="modal-title">Update Employee</h4>
</div>
<div className="container">
<div className="modal-body">
<table>
<tbody>
<tr>
<td>Name</td>
<td> <input type="text"value={ d.Employee_Name} /> </td>
</tr>
<tr>
<td>Address</td>
<td><input type="text" value={ d.Address} /> </td>
</tr>
</tbody>
</table>
</div>
</div>
<div className="modal-footer">
<botton className="btn btn-info"> Update Employee</botton>
<button type="button" className="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</tr>
}
To get the index of item clicked, you need to bind the index to onClick function for each element, like this:
<td>
<center>
<button ... onClick={() => this.props.onClick(i) }></button>
</center>
</td>
Note: replace ... by other properties you are using.
Whenever you click on any item, index i will get passed to this.props.onClick method, you can check that by using console.log in parent onClick function, like this:
onClick(index){
console.log(index); // it will print the index of item clicked
}

Rows Overflow in CGridView Yii

I am using CGridView it's working fine but I have a small prob.
The rows overlap (see screen below), I start using Ecolumns Extension to manage the columns.
But sometime I need to display all the columns and it's not convenient at all (specially on mobile devices)
Here is a JSFiddle example
Does anybody have any idea on how to manage that, in order to make all the rows fit inside the Grid even if all the columns are displayed, please ?
thank you
Edit : The Generated HTML code
<div style="display: none" id="*****-grid-ecolumns-dlg">
<form id="*****-grid-ecolumns" action="/*****/index.php?r=*****" method="POST">
<input type="hidden" value="1" name="*****-grid-ecolumns-set" id="*****-grid-ecolumns-set" />
<ul id="yw1">
<li class="ui-state-default" id="*****"><label><input type="checkbox" name="*****-grid-ecolumns[]" value="****" checked> ****</label></li>
<li class="ui-state-default" id="user_id"><label><input type="checkbox" name="*****-grid-ecolumns[]" value="user_id" checked> User</label></li>
</ul>
<div><input type="submit" onclick="$("#*****-grid-ecolumns-dlg").dialog("close")" style="float: left" name="yt1" value="Apply" />
<input type="button" onclick="$("#*****-grid-ecolumns-dlg").dialog("close"); return false;" style="float: right" name="yt0" value="Close" />
<input type="button" class="reset" value="Reset" style="float: right">
</div></form></div>
<div class="grid-view rounded" id="*****-grid">
<a class="ecolumns-link" id="*****-grid-ecolumns-dlg-link" href="#">Settings</a>
<div class="summary">Displaying 1-50 of 556 results.</div>
<table class="items">
<thead><tr>
<th id="*****-grid_c0">
<a class="sort-link" href="/*****/index.php?r=*****/index&*****_sort=*****_id">*****</a>
</th>
<th id="*****-grid_c1">
<a class="sort-link" href="/*****/index.php?r=*****/index&*****_sort=user_id">User</a></th>
</thead>
<tbody>
<tr class="odd">
<td>*</td><td>*</td>
<td>***</td><td>***</td>
<td>***</td><td></td>
<td></td><td></td>
<td>***</td><td></td>
<td></td><td></td>
<td>***</td><td>***</td>
<td class="button-column"><a class="update" title="Update" href="/*****/index.php?r=*****/update&id=4">
<img src="/******/gr-update.png" alt="Update" /></a>
<a title="Edit" href="****">
<img src="****/home.jpg" alt="edit" />
</a></td></tr>
</tbody></table> </div>
The PHP Code
<?php
$dialog = $this->widget('ext.ecolumns.EColumnsDialog', array(
'options'=>array(
'title' => 'Table Settings',
'autoOpen' => false,
'show' => 'fade',
'hide' => 'fade',
),
'htmlOptions' => array('style' => 'display: none'), //disable flush of dialog content
'ecolumns' => array(
'gridId' => '*****-grid', //id of related grid
'storage' => 'session', //where to store settings: 'db', 'session', 'cookie'
// 'fixedLeft' => array('CCheckBoxColumn'), //fix checkbox to the left side
'model' =>$dataProvider->model, //model is used to get attribute labels
'columns'=>array(
'*****_id',
'user_id',
....
....
array('header'=>'Operations',
'class'=>'CButtonColumn',
'viewButtonImageUrl' => Yii::app()->baseUrl . '/css/gridViewStyle/images/' . 'gr-view.png',
'updateButtonImageUrl' => Yii::app()->baseUrl . '/css/gridViewStyle/images/' . 'gr-update.png',
//'deleteButtonImageUrl' => Yii::app()->baseUrl . '/css/gridViewStyle/images/' . 'gr-delete.png',
'template'=>'{update}{edit}',
),
),
),
));
$this->widget('zii.widgets.grid.CGridView', array(
'id' => '*****-grid',
'dataProvider'=>$dataProvider,
'template' => $dialog->link()."{summary}\n{items}\n{pager}",
'pager' => array('cssFile' => Yii::app()->baseUrl . '/css/gridViewStyle/gridView.css'),
'cssFile' => Yii::app()->baseUrl . '/css/gridViewStyle/gridView.css',
'htmlOptions' => array('class' => 'grid-view rounded'),
'columns' => $dialog->columns(),
//'itemView'=>'_brochureview',
//'columns' => 3
//'filter'=>$model,
));
?>
Here is the additional CSS you need for the table. However, by fitting everything to the width of the window, it will look squishy on smaller screens. This will also make each table cell equal width by default. You may want to use a CSS media query to apply this only to smaller screens.
.grid-view table.items {
width: 100%;
table-layout: fixed;
}
Updated fiddle:
http://jsfiddle.net/37m6ja3v/2/

Resources