Showing Edit/Delete links when hover over the data row - css

I have a table with ng-repeat on the <tr> at with the last td I have edit/delete links, I only want them to show if user hover over the <tr>
<tr ng-repeat="form in allData | filter:search | orderBy: orderByValue : orderIn" ng-click="set_index($index)">
<td><a ng-href={{form.link}}>{{form.ar_ref}}</a></td>
<td>{{form.title}}</td>
<td>{{form.category}}
<span ng-class="{'show_edit_link', $index==selected_index}">
<button ng-click="showUpdate()">Update</button>
<button ng-click="showDelete()">Delete</button>
</span>
</td>
</tr>
My JS Controller:
pp.controller('formsListCtrl', ['$scope', '$http', function($scope, $http){
$http.get('/php_user/formJSON.php').success(function(response){
$scope.allData=response;
//Show hover edit links
$scope.selected_index = 0;
$scope.set_index = function(i){ //i is the $index that we will pass in when hover in the forms_admin.php
$scope.selected_index = i;
}
CSS:
.edit_link_show{
display: inline;
}
.edit_link{
display: none;
}

There is a syntax error in your ng-controller. It should be a : for the expression after class name and you also want to set another ng-class argument for selected_index not equal to $index:
<tr ng-repeat="form in allData | filter:search | orderBy: orderByValue : orderIn" ng-click="set_index($index)">
<td><a ng-href={{form.link}}>{{form.ar_ref}}</a></td>
<td>{{form.title}}</td>
<td>{{form.category}}
<span ng-class="{'show_edit_link': $index==selected_index, 'edit_link': $index!=selected_index}">
<button ng-click="showUpdate()">Update</button>
<button ng-click="showDelete()">Delete</button>
</span>
</td>
</tr>

Related

How to apply a class to a specific label in a row based on truthy value

I'm new to Vue 3. I have a table with rows. See screenshot below. Each row has a checkbox and a label in it. All I want to do is upon initial loading of the page view, have the correct class apply to the label depending on whether the child.status of that row is true-thy or not. Child status true is present. False = absent. Problem: when I initially load the page view all the labels are green regardless whether the child.status false or true.
Currently the Vue 3 code I have got so far works great, except for initial load. If I check the checkbox, I get the data I need and the label gets its green background. If I uncheck a checkbox, the green class disappears. Check it again and the green background reappears - Great. All's well except for initial page load where all the labels are green.
To help you understand I included a screenshot. You will notice behind each label there is a 1 or 0 to indicate whether it is truthy are not. You will see that even the false ones are green.
<template>
<div class="container">
<h5 class="heading ml-4">Children Absent / Present</h5>
<div class="border_charts">
<table class="table ">
<thead>
<tr class="col-4">
<th class="tableHeading col-4">First Name</th>
<th class="tableHeading col-4">Last Name</th>
<th class="tableHeading col-4 ">Absent / Present</th>
</tr>
</thead>
<tbody>
<tr v-for="child in Children" :key="child.child_id">
<td class="col-4"><a :href="'/getchild/'+ child.child_id">{{child.childFirstName}}</a></td>
<td class="col-4"> {{child.childLastName}}</td>
<td class="col-4">
<div class="form-check form-switch" >
<input
type="checkbox"
class="form-check-input"
role="switch"
:id="child.child_id"
v-model="child.status"
:true-value="1"
:false-value="0"
#change="updateChild(child)"
>
<label
class="form-check-label"
v-bind:for="child.child_id "
:class="{present:child.status}"
:true-value="1"
:false-value="0"
> {{ child.status ? absentPresent : absentPresent }}
</label>
{{child.status}}
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</template>
<script>
export default {
props: {
Children:{
Children:Array
},
},
data() {
return {
active:false,
inputClass: 'present',
absentPresent:'Absent/Present'
}
},
methods:{
updateChild(child){
this.changedChild = child;
console.log( this.changedChild);
this.inputClass = 'present'
this.active = ! this.active
},
},
}
</script>
<style scoped>
.present{
background-color: #5ba17a;
border-radius:0.25rem;
width:auto;
color:white;
text-align: center;
margin: 2px;
padding: 0px 5px 0px 5px;
}
.absent{
width:auto;
color:darkblue;
text-align: center;}
</style>
My guess is that child.status is initially loaded as string, so it is '0' instead of 0, and as with any non-empty string, Boolean('0') is true.
Check if you need to convert the values to numbers after loading, or if you can change the data source to send you numbers instead of strings.

Is there any CSS hack to stop a dropdown menu from causing an overflow?

My problem: https://i.gyazo.com/152caf74df3c484e770f9e8c34f5471e.mp4
If I click on the button, then it causes an overflow. I want to menu to appear without the overflow.
Sandbox: https://stackblitz.com/edit/react-ts-8aq1rq?file=App.tsx,index.html
Code:
import * as React from 'react';
import './style.css';
import 'bootstrap/dist/css/bootstrap.min.css';
import { NavDropdown, Button } from 'react-bootstrap';
// #ts-nocheck
export default function App() {
return (
<div className="table-responsive">
<div className="table">
<table
id="user-list-table"
className="table table-striped"
role="grid"
data-toggle="data-table"
>
<thead>
<tr className="light">
<th>Col one</th>
<th>Col two</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>2</td>
<td>
<NavDropdown
id="basic-nav-dropdown"
title={
<Button className="btn btn-sm btn-icon" variant="primary">
click
</Button>
}
>
<NavDropdown.Item>Option 1</NavDropdown.Item>
<NavDropdown.Item>Option 2</NavDropdown.Item>
<NavDropdown.Item>Option 3</NavDropdown.Item>
</NavDropdown>
</td>
</tr>
</tbody>
</table>
</div>
</div>
);
}
Is there another bootstrap component that does this so that I can swap NavDropdown to it? If not, is there something else like a CSS hack that lets me do this?
The issue is that there isn't enough room to dropdown the nav list inside the div with the class of table-responsive. You can give it some min height or padding, but that might be weird if you have content below it. So you can add a negative margin to counter the additional padding:
.table-responsive {
padding-bottom: 100px;
margin-bottom: -100px;
}
Demo

Styling cells in table with react-bootstrap components

I'm rendering a table in which each cell corresponds to a Button component of react-bootstrap.
<>
<Table borderless className='below-nav table-style' responsive="sm">
<tbody>
{Array.from({ length: rows }).map((_, row_index) => (
<tr key={row_index}>
{Array.from({ length: columns }).map((_, column_index) => (
<Button className="td-style button-style" variant="warning">
<td key={column_index}>
ciao
</td>
</Button>
))}
</tr>
))}
</tbody>
</Table>
</>
The problem is that it renders buttons that are not fulfilled with the color selected: variant="warning", but just the border is of that color. There is another issue: bottom-border of each cell is not rendered at all so it seems clearly that something is overlayed on something else but i don't know why.
CSS like this seems not to work:
.table-style {
border-collapse: separate;
border-spacing: 1px ;
border-width: 1px;
}
.td-style {
margin: 5px ;
}
You are wrapping the <td> with the <Button>, this is not the correct way to use a table. This is how it should work:
<>
<Table responsive="sm">
<tbody>
{Array.from({ length: rows }).map((_, row_index) => (
<tr key={row_index}>
{Array.from({ length: columns }).map((_, column_index) => (
<td key={column_index}>
<Button variant="warning">
ciao
</Button>
</td>
))}
</tr>
))}
</tbody>
</Table>
</>
Basic DEMO of a table https://codesandbox.io/s/serene-knuth-qhpuu?file=/src/App.js

Remove all tr elements unless tr>td>input has a class 'DontRemoveMe'

Sorry for the very specific title, couldn't think of how to say it in more general terms.
Assume you have a table and each row contains a cell that has an input, but some input fields have a class of 'DontRemoveMe'. How do you target every row except the 'DontRemoveMe' rows?
Manipulation of DOM Elements requires JavaScript. One way to achieve this is with jQuery:
function remove() {
$('tr:not(.dontRemoveMe)').remove();
}
.dontRemoveMe td {
background-color: green;
}
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
<tr class="dontRemoveMe">
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Jon</td>
<td>Jones</td>
<td>33</td>
</tr>
</table>
<button onclick="remove()">Remove rows</button>
CSS (Not Yet Implemented):
Using CSS level 4 selectors, I believe it would be
tr:has(td>input:not(>>.DontRemoveMe))
However, those aren't implemented in any browser. So you would want to use javascript.
Javascript:
// Select all rows that don't contain a input.DontRemoveMe
let rows = Array.from(document.querySelectorAll("tr")).filter(x => !(x.querySelector("input.DontRemoveMe")));
// Add a special class to these rows so we can target them with CSS
rows.forEach(x => x.classList.add("selected"));
td {
padding: 8px; /* Padding for all rows to make background visible */
}
.selected {
background: red;
}
<table>
<tr>
<td><input type="text" value="selected" />
</td>
</tr>
<tr>
<td><input class="DontRemoveMe" type="text" value="not selected" />
</td>
</tr>
<tr>
<td>
<input type="text" value="selected" />
</td>
</tr>
</table>
Here is an old school javascript way.
Find all the tr tags then find any children with class DontRemoveMe, if it doesn't find any add a .hide class to the current row.
But, honestly I'd question the reason you want to do it like this, chances are there is a more sensible way.
var tr = document.getElementsByTagName('tr');
var i = 0;
var length = tr.length
for (; i < length; i++) {
var dontRemove = tr[i].getElementsByClassName('DontRemoveMe')
if (!dontRemove.length) {
tr[i].classList.add('hide')
}
}
td {
color: #ededed;
}
.red {
background-color: #ff3030;
}
.blue {
background-color: #6495ED;
}
.hide {
display: none;
}
<table>
<tr class="red">
<td>Normal</td>
<td>Normal</td>
<td class="DontRemoveMe">Don't Remove Me</td>
</tr>
<tr class="blue">
<td>Can't see me</td>
<td>Can't see me</td>
<td>Can't see me</td>
</tr>
<tr class="red">
<td class="DontRemoveMe">Don't Remove Me</td>
<td>Normal</td>
<td class="DontRemoveMe">Don't Remove Me</td>
</tr>
</table>

Change of table cell text color based on condition using ng-if and ng-style

I want to display the text in a table cell with alternate color combination depending on some condition as follows.
<tr ng-repeat="x in data">
<td>
<span ng-if="((x.time2 < x.time1) || (x.time2 < x.time3))" ng-style="color:red" {{x.val}}></span>
<span ng-if="((x.time2 === x.time1) && (x.time2 === x.time3)" ng-style="color:blue" {{x.val}}></span>
</td>
</tr>
But i am not getting the value displayed in red color though the x.time2 is less than x.time1. Sample time values are time1="2017-03-15 06:06:56", time2="2017-03-08 07:09:40" and time3="2017-03-08 07:09:40". All time values are in string format.
Try to change your code in this way:
<table>
<tbody>
<tr ng-repeat="x in data">
<td>
<span ng-if="x.time2 < x.time1 || x.time2 < x.time3" ng-style="{color: 'red'}" >{{x.val}}</span>
<span ng-if="x.time2 === x.time1 && x.time2 === x.time3" ng-style="{color: 'blue'}" >{{x.val}}</span>
</td>
</tr>
</tbody>
</table>
I also moved x.val inside span... I don't know if it was an error or not.
Html:
<td [ngClass]="((x.time2 < x.time1) || (x.time2 < x.time3))?'red': (x.time2 === x.time1) && (x.time2 === x.time3)?'green':'black'" >
{{x.val}}
</td>
CSS:
.red {
color: red;
}
.green {
color: green;
}
.black{
color: black;
}

Resources