I am trying to implement a data tables that will show all EMPLOYEE data for 3 tables but I am having issue displaying the data dynamically if triggered by employee.id. I'm trying to get my head aorund this. Any help will be appreciated
`
#bp.route('/employees/show_all/<int:id>')
#login_required
def show_table(id):
success = db.session.query(Employee, Passport, Cerpac).\
select_from(Employee).join(Passport).join(Cerpac).filter(Employee.id==id).all()
return render_template('admin/employees/show-card.html', show_table=show_table, title="Show all Employee" )
--------------------THE LINK------------------------------
<a class="dropdown-item" href="{{ url_for('admin.show_table', id=employee.id) }}"><i class="fa fa-pencil m-r-5">view</a>
--------------------HTML ------------------------------
{% for employee, passport, cerpac in success %}
<tr>
<td> Employeees </td>
<td> {{ employee.first_name }} </td>
<td> {{ employee.last_name }} </td>
----------------------------------------
<td> Cerpac </td>
<td> cerpac.cerpac_serial_no}} </td>
<td> {{ cerpac.cerpac_issue_date}} </td>
-----------------------------------------
<td> Passport </td>
<td> {{ passport.nationality }} </td>
<td> {{ pasport.passport_no }} </td>
------------------------------------------
Related
I would like create dynamic table with value from 2 sql query in postgresql.
From first query I would like to create first 6 row and seven row should be link to files.
First queries I create value2 from which I create table.
<table class="table table-striped table-bordered" id="xxx" width="100%" data-name="mytable">
<thead>
<tr>
<th onclick="sortTable(0, 'xxx')">aaa</th>
<th onclick="sortTable(1, 'xxx')">bbb</th>
<th onclick="sortTable(2, 'xxx')">ccc</th>
<th onclick="sortTable(3, 'xxx')">ddd</th>
<th onclick="sortTable(4, 'xxx')">eee</th>
<th onclick="sortTable(5, 'xxx')">fff</th>
</tr>
</thead>
<tbody>
{% for row in value2%}
<tr>
<td>{{row[0]}}</td>
<td>{{row[1]}}</td>
<td>{{row[2]}}</td>
<td>{{row[3]}}</td>
<td>{{row[4]}}</td>
<td>{{row[5]}}</td>
</tr>
{% endfor %}
</tbody>
</table>
From second query I get value11 as link to files and I would like to set link to this files as last column in tables
{% for plik in value11 %}
<td>
<form action="{{ url_for('static', filename=plik|string +'.xml') }}">
<input type="submit" value="pokaz plik" />
</form>
</td>
{% endfor %}
Can anyone help how create this table?
I try use this code but it's wrong idea ;/
<table class="table table-striped table-bordered" id="czyodramke" width="100%" data-name="mytable">
<thead>
<tr>
<th onclick="sortTable(0, 'xxx')">aaa</th>
<th onclick="sortTable(1, 'xxx')">bbb</th>
<th onclick="sortTable(2, 'xxx')">ccc</th>
<th onclick="sortTable(3, 'xxx')">ddd</th>
<th onclick="sortTable(4, 'xxx')">eee</th>
<th onclick="sortTable(5, 'xxx')">fff</th>
</tr>
</thead>
<tbody>
{% for row in value2%}
{% for plik in value11 %}
<tr>
<td>{{row[0]}}</td>
<td>{{row[1]}}</td>
<td>{{row[2]}}</td>
<td>{{row[3]}}</td>
<td>{{row[4]}}</td>
<td>{{row[5]}}</td>
<td>
<form action="{{ url_for('static', filename=plik|string +'.xml') }}">
<input type="submit" value="pokaz plikl" />
</form>
</td>
</tr>
{% endfor %}
{% endfor %}
</tbody>
</table>
This is how I get value2 and value11
cursor.execute (slq_query)
data2 = cursor.fetchall()
data11 = cursor.fetchall()
data11len = (len(data11))
lst = list(range(data11len))
print (lst)
for i in range (len(data11)):
naszplik = ''.join(data11[i])
with open(f"project/static/{i}.xml", "w", encoding="utf-8") as f:
f.write(naszplik)
return render_template('wyniki.html', value2=data2, value11=lst)
Whenever you use variables from the server in Jinja, you have to surround them in double braces: {{ variable }}. Not doing this will cause Jinja and therefore Flask to ignore your variable. I think you may be missing some braces in a few cases. For example, you do this:
{% for plik in value11 %}
<td>
<form action="{{ url_for('static', filename=plik|string +'.xml') }}">
<input type="submit" value="pokaz plik" />
</form>
</td>
{% endfor %}
You use plik a couple of times, but it's just a string of the word "plik", not the variable assigned to the current iteration of value11. It's very easy to solve, simply wrap in {{ }} and see if that does the trick
My problem isn't second query only that I would like create table form 2 variables like this table:
|aaa |bbb |ccc |ddd |eee |plik |
|aaa1 |bbb1 |ccc1 |ddd1 |eee1 |plik1 |
|aaa2 |bbb2 |ccc2 |ddd2 |eee2 |plik2 |
Now I have 2 different tables:
first table
|aaa |bbb |ccc |ddd |eee |
|aaa1 |bbb1 |ccc1 |ddd1 |eee1 |
|aaa2 |bbb2 |ccc2 |ddd2 |eee2 |
second table
|plik |
|plik1 |
|plik2 |
here is code i am trying to access object of objects.
template
<table class="table table-striped">
<tr *ngFor="let response of response">
<td><b>ID</b><br>{{ response.user_id }} </td>
<td><b>Name:</b> {{ response.first_name }}</td>
</tr>
</table>
The response isn't directly an array. It is an object with properties that contain the array. From the image you posted, you could try the following
<table class="table table-striped">
<tr *ngFor="let customer of response._embedded.customers"> <!-- access properties here -->
<td>
<b>ID</b><br>
{{ customer.user_id }}
</td>
<td>
<b>Name:</b> {{ customer.first_name }}
</td>
</tr>
</table>
What I'm trying to do display some data returned from an API which is working perfectly, but the issue is there is a child object in an object which has to be displayed too and i'm finding difficulty in doing that.
DATA
[{"id":5,"referenceId":1189,"firstName":"Dan","lastName":"Daniels","orders":[{"id":109,"meals":[{"id":47,"name":"Fried Rice","description":"This is a very sweet meal","image":"","mealType":"LUNCH","unitPrice":-20,"status":"ENABLED"}],"serveDate":"2019-07-11 00:00:00"}]}]
HTML
<tbody>
<tr *ngFor="let parent of todayOrder" class="table-row" #row>
<td>
{{parent.firstName}} {{parent.lastName}}
</td>
<td>
<span *ngFor="let child of parent.orders.meals"> {{child.name}}. </span>
</td>
</tr>
</tbody>
The data I want to access is meals which is in orders.
I've tried let child of parent.orders.meals but its not working
you're missing a step in your ngFors, as orders is an array and not an object:
<tbody>
<tr *ngFor="let parent of todayOrder" class="table-row" #row>
<td>
{{parent.firstName}} {{parent.lastName}}
</td>
<td>
<ng-container *ngFor="let order of parent.orders">
<span *ngFor="let child of orders.meals"> {{child.name}}. </span>
</ng-container>
</td>
</tr>
</tbody>
or if you know you only want the first order ever:
<tbody>
<tr *ngFor="let parent of todayOrder" class="table-row" #row>
<td>
{{parent.firstName}} {{parent.lastName}}
</td>
<td>
<span *ngFor="let child of parent.orders[0].meals"> {{child.name}}. </span>
</td>
</tr>
</tbody>
I am getting an error for my html template when using jinja2. Here is the error I get: TypeError: url_for() takes exactly 1 argument (2 given). The error happend in 2 td tags after the endif statement. I tried using an onclick inside a button which is the other way I know how to add a url_for tag.
Here is the template I use:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<table align="center" id="comic_list">
{% for value in bobby %}
<tr>
<td> {{ value[0]|safe }} </td>
<td> {{ value[1]|safe }} </td>
<td> {{ value[2]|safe }} </td>
<td> {{ value[3]|safe }} </td>
<td> {{ value[4]|safe }} </td>
<td> {{ value[6]|safe }} </td>
<td> {{ value[7]|safe }} </td>
</tr>
{% endfor %}
<tr>
<td><button type="submit" value="Next">Next</button></td>
<td><button type="submit" value="Prev">Previous</button></td>
</tr>
</table>
</body>
<footer>
<p align="right">Date/Time: <span id="datetime"></span></p>
<script>
var dt = new Date();
document.getElementById("datetime").innerHTML = dt.toLocaleString();
</script>
</footer>
</html>
Here is the python code used:
#app.route('/test')
def test():
current_page = request.args.get('page', 1, type=int)
comic_dic = {}
per_page = 10
bob = create_bob('Book', 'Yes')
end = (current_page * per_page) + 1
if end > len(bob):
end = len(bob)
start = ((current_page - 1) * per_page) + 1
bob[1:] = sorted(bob[1:], key=lambda v: (v.publisher, v.sort, v.character, v.publication_date, int(v.volume)))
bobby = []
bobby.append(bob[0:1])
for result in bob[start:end]:
bobby.append(result)
next = 'page=' + str(current_page + 1)
prev = 'page=' + str(current_page - 1)
comic_dic['bob'] = bobby
comic_dic['next'] = current_page + 1
comic_dic['prev'] = current_page - 1
return render_template('yes.html', bobby=bobby, next=next, prev=prev)
Thanks Zach
Here's the documentation for url_for():
http://flask.pocoo.org/docs/0.12/api/#flask.url_for
Your problem is that url_for only takes one argument (like the error says). It does however take additional keyword arguments. For example, if you wanted to pass the next and prev variables back the way you currently have it, you'd just need to change your code to look like:
<tr>
<td><button type="submit" value="Next">Next</button></td>
<td><button type="submit" value="Prev">Previous</button></td>
</tr>
This will generate links that look something like:
<tr>
<td><button type="submit" value="Next">Next</button></td>
<td><button type="submit" value="Prev">Previous</button></td>
</tr>
I'm assuming, of course, that the first template you show is passed next and prev variables which are 3 and 1 respectively.
I am trying to displaying the products using Angular JS loop.
<tr ng-repeat="od in OrderDetail">
<td> {{ od.ProductName }} </td><br />
<td align='right'> {{ od.MRP }} </td>
<td align='right'> {{ od.SellPrice }} </td>
<td> {{ od.Quantity }} </td>
<td align='right'> {{ od.Quantity * od.SellPrice | currency:""}}</td>
</tr>
My requirement is display the product name in 1 line, then MRP, sellprice, quantity, total in next line... and so on.
I tried after product name, also i tried using colspan=5 for product name. None of them is working.
Can someone help me on this.
This might be what you want:
<table>
<tbody ng-repeat="od in OrderDetail" >
<tr>
<td colspan="4"> {{ od.ProductName }} </td>
</tr>
<tr>
<td align='right'> {{ od.MRP }} </td>
<td align='right'> {{ od.SellPrice }}</td>
<td> {{ od.Quantity }}</td>
<td align='right'> {{ od.Quantity * od.SellPrice | currency:""}}</td>
</tr>
</tbody>
</table>
And yes, it's okay to have more than one <tbody>
EDIT: It's good practice to use :: for variables in ngRepeat, if you are only changing the entire array (such as renewing the array) and not modifying elements in the array. This will reduce the amount of watchers needed.
You want ng-repeat-start and ng-repeat-end: https://docs.angularjs.org/api/ng/directive/ngRepeat#special-repeat-start-and-end-points