I have an scrollable table in one of my templates defined like this:
JavaScript
x
80
80
1
<script src="{% static 'js/jquery.waypoints.min.js' %}"></script>
2
<script src="{% static 'js/infinite.min.js' %}"></script>
3
<script>
4
var infinite = new Waypoint.Infinite({
5
element: $('.infinite-container')[0],
6
});
7
</script>
8
9
more template
10
11
<div id="table-div" style="overflow: scroll; height: 500px;">
12
<table class="table" id="sale_orders" style="margin-top: 10px; font-size: 10px;">
13
<form class="container py-3" method="GET">
14
<thead>
15
<tr>
16
<th scope="col" class="order_header">Header 1</th>
17
<th scope="col" class="order_header">Header 2</th>
18
<th scope="col" class="order_header">Header 3</th>
19
<th scope="col" class="order_header">Header 4</th>
20
<th scope="col" class="order_header">Header 5</th>
21
<th scope="col" class="order_header">Header 6</th>
22
<th scope="col" class="order_header">Header 7</th>
23
<th scope="col" class="order_header">Header 8</th>
24
<th scope="col" class="order_header">Header 9</th>
25
<th scope="col" class="order_header">Header 10</th>
26
<th scope="col" class="order_header">Header 11</th>
27
<th scope="col" class="order_header">Header 12</th>
28
</tr>
29
</thead>
30
<tbody class="infinite-container">
31
{% for s in sales %}
32
<tr class="infinite-item">
33
<td scope="row"><span class="badge badge-info">{{s.number}}</span></td>
34
<td scope="row">{{s.client_name}}</td>
35
<td scope="row">{{s.comuna}}</td>
36
<td scope="row">{{s.get_total_weigth}}</td>
37
<td scope="row">{{s.get_total_cubic_cm}}</td>
38
<td scope="row">{{s.get_total_area}}</td>
39
<td scope="row">{{s.get_total_amount}}</td>
40
<td scope="row">{{s.get_total_items}}</td>
41
<td scope="row">{{s.product_fam}}</td>
42
<td scope="row">{{s.deliver_date|date:"d/m/Y"}}</td>
43
<td scope="row">
44
{% if s in loadedOrders %}
45
<a class="btn btn-danger update-cart" data-load="{{initLoad.id}}" data-order="{{s.id}}" data-action="remove">
46
<i class="fa fa-download" aria-hidden="true"></i>
47
</a>
48
{% else %}
49
<a class="btn btn-success update-cart" data-load="{{initLoad.id}}" data-order="{{s.id}}" data-action="add">
50
<i class="fa fa-upload" aria-hidden="true"></i>
51
</a>
52
{% endif %}
53
</td>
54
<td scope="row">
55
{% if s in loadedOrders %}
56
<a data-toggle="modal" data-target="#lines_info_{{s.id}}">
57
<input type="button" name="partial_selection" value="Selección parcial" id="button{{s.id}}" class="btn btn-warning">
58
</a>
59
{% else %}
60
<a data-toggle="modal" data-target="#lines_info_{{s.id}}">
61
<input type="button" name="partial_selection" value="Selección parcial" id="button{{s.id}}" class="btn btn-warning" disabled>
62
</a>
63
{% endif %}
64
</td>
65
</tr>
66
{% endfor %}
67
68
{% if sales.has_next %}
69
<tr>
70
<td scope="row" colspan="12" style="text-align: center;">
71
<a class="infinite-more-link" href="?page={{ sales.next_page_number }}">More</a>
72
</td>
73
</tr>
74
{% endif %}
75
</tbody>
76
</form>
77
</table>
78
</div>
79
80
more template
And my view is defined like this:
JavaScript
1
53
53
1
def optimizer(request, pk):
2
sids = []
3
settings = Setting.objects.get(pk=1)
4
trucks = Truck.objects.all()
5
6
for s in SaleOrder.objects.filter(delivered=False):
7
if s.get_total_items > 0:
8
sids.append(s.id)
9
10
sales = SaleOrder.objects.filter(pk__in=sids).order_by('-id')
11
12
lines = SaleOrderLine.objects.filter(delivered=False, order_id__in=sids)
13
14
min_load = settings.minimum_load_percentage
15
min_value = settings.minimum_total_amount
16
17
page = request.GET.get('page', 1)
18
paginator = Paginator(sales, 20)
19
try:
20
sales = paginator.page(page)
21
except PageNotAnInteger:
22
sales = paginator.page(1)
23
except EmptyPage:
24
sales = paginator.page(paginator.num_pages)
25
26
initLoad = Load.objects.get(pk=pk)
27
loadedOrders = initLoad.order_ids.all()
28
loadedLines = initLoad.line_ids.all()
29
30
if request.GET.get('selected_lines') and request.GET.get('truck_selector'):
31
lids = request.GET.getlist('selected_lines')
32
alllines = SaleOrderLine.objects.filter(pk__in=lids, order_id__in=loadedOrders)
33
for l in loadedLines:
34
if l not in alllines:
35
initLoad.line_ids.remove(l)
36
37
truck = Truck.objects.get(pk=request.GET.get('truck_selector'))
38
initLoad.truck_id = truck
39
initLoad.state = 'preview'
40
initLoad.save()
41
return redirect('optimizer', pk=initLoad.id)
42
43
data = {
44
'trucks': trucks,
45
'sales': sales,
46
'lines': lines,
47
'initLoad': initLoad,
48
'loadedOrders': loadedOrders,
49
'step': initLoad.state,
50
}
51
52
return render(request, 'optimizer/main_optimizer.html', data)
53
So, I followed the tutorial posted on here, but when I get to the table bottom, nothing happens.
I don’t get why is not loading the rest of the data when I get to the ‘waypoint’. Any suggestion or new solution for this it would be appreciated.
Thanks.
Advertisement
Answer
Try putting your var infinite = new Waypoint
script after the html <tbody class="infinite-container">
Currrently, when it is called, the element of that class hasn’t been created yet.