Issue setting up grid style results - html

I want to show a table in a grid result table and I am failing...
I want it to look like so:
I'm trying to do it this way, but it only shows one line:
<div class="resultsTable">
<table style="display: inline-table">
<tr ng-repeat="result in results" class="resultsBox">
<td>
<img src="{{result.imageUrl}}" width="200px">
<h4>{{result.name}}</h4>
</td>
</tr>
</table>
</div>
CSS:
.resultsBox{
background-color: #ffffff;
height: 200px;
width: 200px;
padding-left: 10px;
padding-top: 20px;
}
.resultsBox>img{
max-width: 200px;
margin-left: auto;
margin-right: auto;
}
.resultsTable{
max-height: 500px;
overflow: scroll;
display: inline-table;
height: 500px;
}

From the template you have shared it's normal that you see only one column of n row. It is not link to the css but to the markup that will be generated.
Your results property is an array of one dimension something like [{obj1}, {obj2}, {obj3}] but you want to display a matrix an array of two dimensions i.e [[{obj1}, {obj2}], [{obj3}, {obj4}]]. Unfortunately it is not that easy in AngularJS to generate a matrix based on a one dimension array. That's why I will recommend that you change the structure of your result to match its matrix display. Then change your template to something like :
<div class="resultsTable">
<table style="display: inline-table">
<tr ng-repeat="row in results"> //loop over all row of 2 elements
<td ng-repeat="cell in row" class="resultsBox"> //loop over elements
<img src="{{cell.imageUrl}}" width="200px">
<h4>{{cell.name}}</h4>
</td>
</tr>
</table>
</div>
See a working plunker here

Related

html table: row 2 alters the length of row 1

I am trying to create a tree with a three elements. Main Element, -> children, -> children.
I got pretty far, I can even collaps entire portions of the table. The problem however is, when I collabs row two.
At first, the table looks like this:
Which is fine. I have three <td> in one row.
However, if I show the second row (clicking on my blue arrow),
this is the result:
So, what happens is that the second <tr> then pushes the elements of the second <td> so much forward, that "SubKategorie_1 DELETE" has enough room to fit before "Hauptkategorie_1" begins, which is in a different table row.
I am pretty sure that all I need is a css attribute.
Ill give you the code shortend:
<table class="mainTable">
#{
var position = 0;
for (int i = 0; i < Model.MainNodes.Count(); i++)
{
string catId = "CatId" + i.ToString();
string classToHideCatId = "classToHideCatId" + i.ToString();
<tr class="mainCatRow">
<td>
<div>
<img src="#Url.Content("~/Content/images/icons/icon-open.png")" id="#catId" class="buttonLayoutMain" />
</div>
</td>
<td>
<div class="mainCat">
#Model.MainNodes[i].name
</div>
<td>
Delete
</td>
</tr>
<!--subcategory-->
<tr class="tr2">
<td>
<div class="#classToHideCatId">
<table class="subTable">
...
</table>
</div>
</td>
</tr>
}
}
</table>
With some basic CSS:
.MainDiv{
padding: 20px;
}
.mainTable{
background-color: green;
}
.mainCat {
font-size: 20px;
}
.mainCatRow{
background-color:orange;
}
.subCat {
margin-left: 40px;
font-size: 18px;
}
.tr2{
background-color:gray;
}
.subsubTable {
margin-left: 80px;
}
Question:
How can I make my table have differnt lenght rows?

Prevent td Element From Growing to Fit Child Elements

I am trying to make a table with drop-down info tabs that appear when you scroll over a term.
My initial approach was to make these info tabs not display with display : none css rule, then
when the user hovers the mouse over the corresponding text, the the info tab appears by altering display property to display: block.
My problem is that I can't figure out how to override the default behavior for the containing/parent element, and the table resizes to fit the newly appeared element, then resizes back to normal when the user scrolls away. I experimented with z-index (setting the td to z-index: 1 and info tab to z-index:2) as well as visibility:hidden -> visibility:visible vs display:none -> display:block, but no luck with either of those. I also tried setting the max height of the td element to 200px, but it seems to grow past that regardless.
Here is the source code for what i have so far:
/* In an attempt to prevent row from expanding automatically */
td {
max-height: 100px;
}
.card-body {
display: none;
border: 2px solid black;
height: 300px;
width: 400px;
z-index: 2;
}
.card-trigger:hover+.card-body {
display: inline-block;
position: relative;
top: 0px;
right: 15px;
}
.card-body:hover {
display: block;
}
.card-body .game-info {
display: none;
}
.card-body .dd-trigger:hover+.game-info {
display: block;
}
<h3>Ratings by som bol</h3>
<p>sort by release date (asc/desc), rating amout, game category, game creator, game console</p>
<input type="text" placeholder="filter by game title, categories, creators, consoles, console makers">
<div>Search hints</div>
<table class="table">
<thead>
<tr>
<th>Game title</th>
<th>your rating</th>
<th>Average rating</th>
<th></th>
</tr>
</thead>
<tbody>
<!-- Row 1 -->
<tr>
<td>
<a class="card-trigger" href="#">Some Videogame</a>
<div class="card-body">
<img src="#" alt="picture of the game in question" />
<h3><a [routerLink]="">Game title</a></h3>
<p>Some stuff happens and you have fun</p>
<span class="dd-trigger">Show more info</span>
<ul class="game-info">
<li>Average Rating: </li>
<li>Average Review Score: </li>
</ul>
</div>
</td>
<td>
your rating : 2
</td>
<td>
average rating : 3
</td>
<td><button>Delete rating</button></td>
</tr>
<!-- Row 2 -->
<tr>
<td>
<a class="card-trigger" href="#">Some Videogame</a>
<div class="card-body">
<img src="#" alt="picture of the game in question" />
<h3><a [routerLink]="">Game title</a></h3>
<p>Some stuff happens and you have fun</p>
<span class="dd-trigger">Show more info</span>
<ul class="game-info">
<li>Average Rating: </li>
<li>Average Review Score: </li>
</ul>
</div>
</td>
<td>
your rating : 2
</td>
<td>
average rating : 3
</td>
<td><button>Delete rating</button></td>
</tr>
<!-- row 3 -->
<tr>
<td>
<a class="card-trigger" href="#">Some Videogame</a>
<div class="card-body">
<img src="#" alt="picture of the game in question" />
<h3><a [routerLink]="">Game title</a></h3>
<p>Some stuff happens and you have fun</p>
<span class="dd-trigger">Show more info</span>
<ul class="game-info">
<li>Average Rating: </li>
<li>Average Review Score: </li>
</ul>
</div>
</td>
<td>
your rating : 2
</td>
<td>
average rating : 3
</td>
<td><button>Delete rating</button></td>
</tr>
</tbody>
</table>
In order to prevent parents from resizing to fit the contained element, you must do three things:
Set parent position to relative
Set child position to absolute (and position in appropriate place using top, bottom, left, right)
Set child element z-index higher than that of parent. We do this to prevent any parent styles from overlapping with child styles. It essentially makes the child element look like it is sitting on top of the parent element.
the html is a trivial example of a table with one row. the css hides the contained child div by default, and sets the display to block when hovering, in addition to default styles and the positioning/z-index mentioned above
table, th, td {
border: 1px solid black;
}
.pop-up {
display: none
}
td {
position: relative;
}
td:hover > .pop-up {
display: block;
}
.pop-up {
width: 500px;
height: 100px;
background: red;
border: 1px solid black;
position: absolute;
left: 50px;
z-index: 1;
}
click here to see full example

HTML table; How to format content within 2nd column to align all - except first element - to right and stretch 1st element to fill remaining width

want to display the following:
where the "..." button in the first row (Web Project) is completely right-aligned to the red line (with a little padding to it)
where the Input field in the 2nd row (Root Namespace) is filling up the space to the right until the red line (with a little padding to it)
where the 2 buttons in the 3rd row (Connection String) are completely right-aligned to the red line (with a liddle padding to it).
I have tried the following but it does not do it correctly - and it only works with a certain width - If I increase or decrease the width, things are getting ugly:
decreasing the width:
My current HTML looks like this:
<div id = "ProjectSelector" width = 100%>
<table width = "100%" style = "padding-bottom: 10px;">
<tr>
<td style="white-space: nowrap; width: 140px;">Web Project (.csproj)</td>
<td style="width: 99%;" ><input id = "webproj" style="width: 97%"/><button id="webproj_browse">...</button></td>
</tr>
<tr>
<td>Root Namespace</td>
<td style="width: 99%;"><input id = "rootnamespace" style="width: 99%"/></td>
</tr>
<tr>
<td>Connection String</td>
<td style="width: 99%;"><select id = "connectionstring" style = "width: 87%"></select><button id="newConnection">New Connection</button><button id="connstringDelete">Delete</button></td>
</tr>
</table>
</div>
Question: How to format the table and the content of 2nd column to accomplish this properly?
the title of your question describes a typical flex behavior. You may use inside your table a flex container :
.flex {
display: flex;
}
.flex-1 {
flex-grow: 1;
}
<div id="ProjectSelector" width=1 00%>
<table width="100%" style="padding-bottom: 10px;">
<tr>
<td style="white-space: nowrap; width:0;">Web Project (.csproj)</td>
<td>
<div class="flex"><input id="webproj" class="flex-1" /><button id="webproj_browse">...</button></div>
</td>
</tr>
<tr>
<td>Root Namespace</td>
<td>
<div class="flex"><input id="rootnamespace" class="flex-1" /></div>
</td>
</tr>
<tr>
<td>Connection String</td>
<td>
<div class="flex">
<select id="connectionstring" class="flex-1"></select><button id="newConnection">New Connection</button><button id="connstringDelete">Delete</button></div>
</td>
</tr>
</table>
</div>
It can also be build with grid or flex without a table.
For infos & demo , an example mixing grid and flex, i would probably not use this HTML structure H + P at first :
* {
margin: 0;
}
.flex {
display: flex;
}
.flex-1 {
flex-grow: 1;
}
#ProjectSelector {
display: grid;
grid-template-columns: auto 1fr;
grid-gap: 0.25em;
;
}
p {
grid-column: 2;
}
<div id="ProjectSelector">
<h4>Web Project (.csproj)</h4>
<!-- title that matches your structure or else can be plain text -->
<p class="flex"><input id="webproj" class="flex-1" /><button id="webproj_browse">...</button></p>
<h4>Root Namespace</h4>
<p class="flex"><input id="rootnamespace" class="flex-1" /></p>
<h4>Connection String</h4>
<p class="flex">
<select id="connectionstring" class="flex-1"></select><button id="newConnection">New Connection</button><button id="connstringDelete">Delete</button></p>
</div>

How can I highlight on mouse click selected row of the table using Bootstrap 4 and Angular 6?

I have a Bootstrap table using table-hover and everything works properly .table-hover enables a hover state on table rows within a <tbody>. I also have this method:
listClick(event, newValue) {
this.UploaderService.getFileName(newValue[1])
}
which sets name of the file from the specified row and then other methods from
UploaderService uses this variable to execute specified operations like deleting, uploading etc.
My problem is that everything works fine, unfortunately the line being clicked is not highlighted so the user is not completely aware of the selected row. I would like to leave this line highlighted at the moment of clicking a specific action on this object, such as deleting etc.
Furthermore I would like to have a possibility to select multiple rows using combination for instance of mouse clicking + cmd in case of mac os. Any ideas how can I do this?
<div style="display: block;" class="table-div content table-responsive table-full-width" >
<table class="Table table table-hover">
<div>
<thead >
<tr >
<th style="width: 20vw; min-width: 150px; text-align: left " *ngFor="let cell of this.UploaderService.tableData2.headerRow">{{ cell }}</th>
</tr>
</thead>
</div>
<tbody style=" overflow:auto; height:60vh; margin-bottom:1vh; display: block; left: 0vw; right: 0vw">
<tr *ngFor="let item of this.UploaderService.uploader.queue">
<td><button type="button" (click)="item.remove()">Cancel</button>
<div class="progress">
<div class="progress-bar bg-success"
[ngStyle]="{'width':item.progress+'%'}"></div>
</div>
</td>
<td>
<div >{{item.file.name}}</div>
</td>
<td>
<div >{{item.file.size}}</div>
</td>
<td>
<div >{{item.file.type}}</div>
</td>
<td>
<div >{{item.file.lastModifiedDate}}</div>
</td>
<tr *ngFor="let row of this.UploaderService.tableData2.dataRows">
<td [ngClass]="{'active': selectedItem == cell}" (click)="listClick($event, row)" (dblclick)="listDoubleClick($event, row)" style="cursor: pointer; width: 20vw; min-width: 150px; text-align: left" *ngFor="let cell of dateFormat(row)">{{cell}}</td>
</tr>
</tbody>
</table>
</div>
I try like this:
ts:
listClick(event, row) {
row.isSelected = !row.isSelected;
this.UploaderService.getFileName(row[1])
}
html:
<tr *ngFor="let row of this.UploaderService.tableData2.dataRows">
<td [ngClass]="{'active': row.isSelected}" (click)="listClick($event, row)" (dblclick)="listDoubleClick($event, row)" style="cursor: pointer; width: 20vw; min-width: 150px; text-align: left" *ngFor="let cell of dateFormat(row)">{{cell}}</td>
</tr>
A simple way is just to add one attribute like:
isSelected: boolean to you dataRows when one or more of them is selected;
listClick(event, newValue, cell) {
cell.isSelected = !cell.isSelected;
this.UploaderService.getFileName(newValue[1])
}
but i highly recommend you to use this excellent data table in angular
ngxDataTable
hope it help.
In bootstrap 5 you need to use bootstrap class "table-active".
html:
<tr [class.table-active]="i == currentRowIndex" *ngFor="let row of this.UploaderService.tableData2.dataRows; let i = index" (click)="onRowClick(i)">
ts:
currentRowIndex: number = -1;
onRowClick(index: number) {
this.currentRowIndex = index;
}

Setting fixed height for all rows of the table

I have created a table http://jsfiddle.net/vR5B8/.
table id="resultDetails" class="table-striped" border=1 width="99%" nowrap=0; cellspacing=0; cellpadding=3><tbody>
<th colspan="2"><Big>Result Details</Big></th>
<tr data-depth=0 class="collapse" height=1px >
<td width="4%">P</td>
<td width="80%">Modules
<div class="content">
<p>Abc</p>
</div>
</td>
</tr>
<tr data-depth=0 class="collapse" height=1px >
<td width="4%">P</td>
<td width="80%">Modules 1</td>
</tr>
<tr data-depth=0 class="collapse" height=1px >
<td width="4%">P</td>
<td width="80%">Modules 2</td>
</tr>
</tbody>
Some of the rows contain additional information which is hidden. If the row contains hidden information, then the height of row is increasing compare to the row which does not contain the hidden information. How to set the common height for all rows.
Any thoughts ?
Use display: none instead of visibility hidden demo
tr {
height: 50px;
}
for example :) or
tr {
height: auto;
}
depends of what you need :)
The table row height will increase dynamically in height if more information is added, but to hide an element, use display: none and to give a height to a row, use line-height: /* size */;
.content {
display:none;
}
tr {
min-height: 20px;
line-height: 20px;
}
Here's the jsFiddle