make a row clickable in html - html

I am trying to make a table's rows clickable, by calling a controller (am using symfony) and i found this solution, but the problem i have is that even the titles of the row is clickable and leads me to an error, and the other problem is that when i customize the hover it's applied on all the rows even if i use a class or specified the style inside the <tr>
Here is my code
<table class="table table-hover ">
<thead>
<tr>
<th>N°</th>
<th>Titre</th>
<th>Date</th>
</tr>
</thead>
<tbody>
{% for key, rech in recherche %}
<tr style="cursor: pointer;">
<td>{{ loop.index }}
</td>
<td>{{ rech.titre | raw }}</td>
<td>{{ rech.date | date('Y-m-d') |raw }}</td>
</tr>
{% endfor %}
</tbody>
</table>
Thanks for your response.

You can try this solution below.
EDIT
Make sure you add this reference in your header section
EDIT
put the js code in a file, and put this at the bottom of the page before the body close.
<script src="/path/filename.js">
Goes in the header
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
DEMO
<table class="table table-hover ">
<thead>
<tr>
<th>N°</th>
<th>Titre</th>
<th>Date</th>
</tr>
</thead>
<tbody>
{% for key, rech in recherche %}
<tr data-href="{{ path('resultat',{'id':rech.id}) }}">
<td>{{ loop.index }}</td>
<td>{{ rech.titre | raw }}</td>
<td>{{ rech.date | date('Y-m-d') |raw }}</td>
</tr>
{% endfor %}
</tbody>
</table>
js
$(function(){
$(document).on('click', '[data-href]', function () {
var url = $(this).data('href');
if (url && url.length > 0) {
document.location.href = url;
return false;
}
});
});
css
.table-hover tbody tr {
background: #dcdcdc;
pointer: cursor;
}

hello we just add the link for Jquery
<script src="../jquery.min.js"></script>
<table>
<thead style="display: none">
<tr>
<th>Id</th>
<th>Name</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for project in projects %}
<tr class="tablerowproject" data-href="{{ path('company_index') }}">
<td><i class="step fi-lightbulb" style="font-size: 60px; color: #FBFCF7 "></i></td>
<td>{{ project.name }}</td>
<td>
<ul>
<li>
show
</li>
<li>
edit
</li>
</ul>
</td>
</tr>
{% endfor %}
</tbody>
</table>
and add this lines
<script type="text/javascript">
$(document).ready(function(){
$(".tablerowproject").click(function() {
window.document.location = $(this).data("href");
});
})
</script>
add in your file CSS add this
.tablerowproject {
display: block;
background-color: #345d71;
border-radius: 5px;
cursor: pointer;
}
.tablerowproject:hover{
background-color: #092636;
}
and this my result

Related

Bootstrap datatables - multi-filter column search CSS issue

What I am doing is to render table in HTML from Flask server. Bootstrap code I have referred to is from this link:
Bootstrap multi-filter
my HTML code:
<table id="example" class="table table-striped">
<thead>
<tr>
<th scope="col">Index</th>
<th scope="col">Col2</th>
<th scope="col">Col3</th>
<th scope="col">Col4</th>
</tr>
</thead>
<tbody>
{% for item in rows %}
<tr>
<td><form action="/get1" method="POST"><button formtarget="_blank"
name="input" type="submit"
formaction="/get1"
value={{item[0]}}>{{item[0]}}</button>
</form>
</td>
<td>{{ item[1] }}</td>
<td>{{ item[2] }}</td>
<td>{{ item[3] }}</td>
</tr>
{% endfor %}
</tbody>
<tfoot>
<tr>
<th>Index</th>
<th>Col2</th>
<th>Col3</th>
<th>Col4</th>
</tr>
</tfoot>
</table>
I have exactly the same JS files as shown in the Bootstrap website.
My objective is to get the search label and input box to the left, and 'show entries per page' label and dropdown to the right. For this I tried using following additional CSS, but it did not work as intended.
<style>
.dataTables_wrapper .col-md-6:nth-of-type(1){
order: 2;
}
div.dataTables_wrapper div.dataTables_filter label {
text-align: left;
}
div.dataTables_wrapper div.dataTables_filter input {
width: 100%;
margin: 5px;
}
div.dataTables_wrapper.dataTables_length select input{
width: 100%;
}
</style>
When I open page it shows like this:
enter image description here
Where as my objective is to show the search box and #entries box as follows:
enter image description here
I need some help to correct my CSS to achieve placing search on left and entries on right.

How to make one column fixed and the other one scrollable

I have tried to make a page where one column is fixed and the other one is scrollable. In the template "Os name" and "{{ i.os_name }}", I want to make it fixed. All the other ones should be scrollable.
I have tried some solutions but I'm facing issues. I have pasted the CSS which I have tried. Please tell me where I am going wrong so I can make it correct.
<div>
<table class="table accountTable" id="book-table" cellpadding="0" cellspacing="0" style="width: 91%;">
<thead>
<tr class="accountBorder">
<th class="osfix">Os Name</th>
<th class="">Browser</th>
<th>IP Address</th>
<th>Location</th>
<th>Session Time</th>
<th>Activity</th>
</tr>
</thead>
<tbody>
{% for i in account %}
<tr>
<td><div class="osfixName">{{ i.os_name }}</div></td>
<td>
<div class = "title_elipses accordion">{{ i.browser }}</div>
<div class="panel" style="display: none;"><p>{{i.browser}}</p></div>
</td>
<td>
<div>{{ i.ip_address }}</div>
</td>
<td>
<div>{{ i.city }}, {{ i.country }}</div>
</td>
<td>
{% for key,value in some_date.items %}
{% if i.id == key %}
<!-- here we are displaying the age of the ad -->
<span class="dealpagetext">{{ value }}</span><br>
{% endif %}
{% endfor %}
<!-- <div>{{ i.last_loggedin }}</div>-->
</td>
<td>
{% if i.activity == 1 %}
<div>Signout</div>
{% else %}
<div></div>
{% endif %}
</td>
</tr>
{% empty %}
<tr>
<td colspan="7" class="text-center">No History</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
css
#book-table {
width: 131% !important;
margin-left: 111px;
}
.osfix {
position: fixed;
left: 0;
background-color: #ddd;
padding-left: 4px;
}
.osfixName {
position: fixed;
left: 0;
padding-left: 4px;
z-index: 88;
background-color: #fff;
}

unable to remove white space from HTML view with Bootstrap

I'm having an issue with the template view below. I've added a scrollbar to the "Used in" table at the bottom, however I am getting a lot of whitespace underneath it. When I try removing each div/element one by one the issue seems to come from that table alone.
view.html
{% extends "includes/base.html" %}
{% load crispy_forms_tags %}
{% block body %}
<div class="container-fluid">
<div class="row">
<div class="col">
<form method="POST">
<br>
{% csrf_token %}
{% crispy partform %}
</form>
<br>
<table class="table table-hover">
<tbody>
{% for comment in partcomments %}
<tr>
<td>{{ comment }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<form method="POST">
<br>
{% csrf_token %}
{% crispy commentForm %}
</form>
<div>
{% for image in images %}
<img class="center img-responsive" src="{{ image.image.url }}"
style="height: 25%"/>
{% endfor %}
<br>
<form enctype="multipart/form-data" method="post">
{% csrf_token %}
{{ imageform.as_p }}
<button type="submit">Upload</button>
</form>
</div>
</div>
<div class="col">
<div class="table-wrapper-scroll-y my-custom-scrollbar">
<table class="table table-hover mb-0">
<thead>
<tr>
<th>Supplier</th>
</tr>
</thead>
<tbody>
{% for supplier in partsuppliers %}
<tr data-href="{% url 'info_supplier' supplier.supplier.id %}">
<td>{{ supplier }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<a class="btn btn-secondary btn-sm btn-pad" href="{% url 'addpartsupplier' part_id=part_id %}"
role="button">Add
Supplier</a>
<div class="table-wrapper-scroll-y my-custom-scrollbar">
<table class="table table-hover mb-0">
<thead>
<tr>
<th>Movements</th>
</tr>
</thead>
<tbody>
{% for movement in movements %}
<tr>
<td>{{ movement.history_date }}</td>
<td>{{ movement.history_user }}</td>
<td>{{ movement.change }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<div class="table-wrapper-scroll-y my-custom-scrollbar">
<table class="table table-hover mb-0">
<thead>
<tr>
<th>Used in</th>
</tr>
</thead>
<tbody>
{% for activity in activities %}
<tr>
<td>{{ activity.group.groupName }}</td>
<td>{{ activity.activity.activityName }}</td>
<td>{{ activity.qty.quantity__sum }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
{% endblock %}
I have a custom.css file served in the static folder that is loaded in the base.html as per below. The issue arises only in this view as I've tried removing the base.html and haven't found any overflow issues in my other template views
custom.css
.my-custom-scrollbar
{
position: relative;
max-height: 25%;
overflow: auto;
}
.table-wrapper-scroll-y {
display: block;
}
.center {
display: block;
margin-left: auto;
margin-right: auto;
}
I think I'm not including something in the CSS. any help would be appreciated.
Edit: Picture added below for clarification. Lots of whitespace that extends to where the table ends without the y scroll.
Bootstrap applies a margin-bottom of 20px to the ".table" class. If you inspect the table in the console - you will be able to see that styling.
In order to remove this- you will need to over-ride the style rule in your own styling (note that this MUST be after the Bootsrtrap styles are imported).
.table {
margin-bottom: 0;
}

how to get elements in separated rows in html table?

Hey i am fetching data from excel file but all the data is returning in only one row box this is my html code
{% block body %}
# i am using bootstrap table class
<table class="table table-bordered">
<thead>
<tr>
<th scope="col">Pensioner name</th>
<th scope="col">cnic</th>
<th scope="col">mobile</th>
<th scope="col">wallet</th>
</tr>
</thead>
<tr>
{% if 'm1' %}
<td><h6 >{{ m1 }}</h6></td>
{% endif %}
{% if 'm2' %}
<td><h6 >{{ m2 }}</h6></td>
{% endif %}
{% if 'm3' %}
<td><h6 >{{ m3 }}</h6></td>
{% endif %}
{% if 'm4' %}
<td><h6 >{{ m4 }}</h6></td>
{% endif %}
</tr>
</table>
{% endblock %}
this is my outputenter image description here
i want data into separate rows boxes now it looks to messy please help
To create a new row you would need to add a new <tr> element for each row.
Here is a working example
table,
tr,
th,
td {
border: solid 1px;
}
<table>
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Job Title</th>
</tr>
</thead>
<tbody>
<tr>
<td>James</td>
<td>Matman</td>
<td>Chief Sandwich Eater</td>
</tr>
<tr>
<td>The</td>
<td>Tick</td>
<td>Crimefighter Sorta</td>
</tr>
</tbody>
</table>
Each <tr> element inside the <tbody> element creates a new row.

Vue.js component does not receive prop

I would like to pass a ride to the show-ride-modal. When somebody clicks on the button show a modal will pop-up with the ride information.
<table class="table">
<thead>
<tr>
<th>Door</th>
<th>Van</th>
<th>Naar</th>
<th>Type</th>
<th>Datum</th>
</tr>
</thead>
<tbody>
<tr v-for="ride in rides">
<show-ride-modal :ride="ride"></show-ride-modal>
<td>{{ ride.user.name }}</td>
<td>{{ ride.location.from }}</td>
<td>{{ ride.location.to }}</td>
<td>{{ ride.type.name }}</td>
<td>{{ ride.date }}</td>
<td>
<a #click="show" class="btn-show">show</a>
<a v-link="{ name: 'ritten' }" class="btn-edit">Bewerk</a>
<a v-link="{ name: 'ritten' }" class="btn-delete">Remove</a>
</td>
</tr>
</tbody>
</table>
My show ride modal component:
<template>
<modal title="Bekijk rit">
<form class="Modal__form" #submit.prevent="createTopic">
<p>test</p>
<p>{{ ride.user.name }}</p>
</form>
</modal>
</template>
<script>
import Modal from './Modal.vue'
export default {
components: { Modal },
props: ['ride'],
data () {
return {
showLoader: false
}
}
}
</script>
The problem is that the ride is not being passed to the <show-ride-modal>. What could be wrong?