admin 管理员组文章数量: 1086019
Good day everyone!
I've been looking around the web on how to load more rows in the table on scroll down reached the bottom, but unfortunately, I only see divs tutorial. Can anyone please enlighten me how to execute this? or a sample code or tutorial?
It's like this, I will run a SELECT query and LIMIT the showing to 500 records only in the html table, but when the user scrolls down to the bottom of the table, the record will load another 500 records on the table. Is this possible?
Good day everyone!
I've been looking around the web on how to load more rows in the table on scroll down reached the bottom, but unfortunately, I only see divs tutorial. Can anyone please enlighten me how to execute this? or a sample code or tutorial?
It's like this, I will run a SELECT query and LIMIT the showing to 500 records only in the html table, but when the user scrolls down to the bottom of the table, the record will load another 500 records on the table. Is this possible?
Share Improve this question asked Mar 13, 2018 at 4:10 DarwinDarwin 451 silver badge6 bronze badges 1-
1
what you ask is not trivial... Not to do it right, which includes cashing some of the results.. And yes its possible it's called
append
to the table, the difference between a div and this is minor. – ArtisticPhoenix Commented Mar 13, 2018 at 4:15
2 Answers
Reset to default 4
$('#container').on('scroll', function() {
if($(this).scrollTop() + $(this).innerHeight() >= $(this)[0].scrollHeight) {
alert('end reached');
}
});
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis./ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<style type="text/css">
#container{
overflow: scroll;
max-height: 500px;
border: 2px solid;
}
</style>
</head>
<body>
<div id="container">
<table>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
<tr>
<td>hi</td>
<td>hello</td>
</tr>
</table>
</div>
</body>
</html>
The code above will detect when the scroll will reach the end of the table. now you can replace alert()
with an $.post()
or $.ajax()
to fetch more results from database and append
the response in the table
$(document).on('click','#load',function(){
$('#loading').append('<tr><td>3:1</td><td>3:2</td><td>3:3</td></tr>');
})
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id="loading">
<tr><td>1:1</td><td>1:2</td><td>1:3</td></tr>
<tr><td>2:1</td><td>2:2</td><td>2:3</td></tr>
</table>
<input type="button" value="click to append" id="load"/>
Zainul described about Creating an event handler.
This answer about appending to table.
Merge this two answers.
本文标签: javascriptLoad more table rows on scroll downStack Overflow
版权声明:本文标题:javascript - Load more table rows on scroll down - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744060336a2526611.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论