当前位置:网站首页>Use the aggird component to implement sliding request paging to achieve the effect of infinite scrolling
Use the aggird component to implement sliding request paging to achieve the effect of infinite scrolling
2022-08-06 07:52:58【Zhuobailou】
aggirdComponents is a powerful form show,No matter how many data backend back,It can only show the user see article number,Thus improve the fluency of improving the user experience.
但是当数据过多时,Backend one-time return all of the data will make interface request time slow,从而产生等待.So the back-end usually solve this problem is to do a page,前端传递pagesize和pageindexTo partial request data.So the question is how do we useaggirdForm component implementation falling demand paging so as to realize the infinite scroll effect.
Website puts forward two solutions,One is the infinite scroll(企业版需要money),Is a kind of infinite line scheme,Here I briefly the line wireless solution.
The following is an example of a website and address,What do you mean go to website to see the specific parameters.That may be you have a question,Went to the website to see what's your meaning this blog.
Examples of website of infinite line is wireless line effect,But it is a request back all data,And then partitioned loading.Which is the effect of rolling paging,But the line is really a request back-end data.Do not implement the back-end to the effect of the paging request,So we're going to fit in this transformation on the basis of the
从官网得知getRowsEach time the grid needs more row,会调用getRows方法,I also see each scroll to the bottom in the console when you callgetRows方法.So we can from this exploit,在getRows里调用接口,Each slide to the bottom is called a interface,So as to realize wireless scrolling effect
好了,现在思路有了,剩下的就是搞清楚getRowsWhat is the meaning of the inside of the parameters are,We can see in the sample
const {
startRow,endRow } =params
const rowsThisPage = data.slice(startRow,endRow)
// const rowsThisPage = data.sstartRowlice(params.startRow, params.endRow);
// if on or after the last page, work out the last row.
let lastRow = -1;
if (data.length <= endRow) {
lastRow = data.length;
}
这里的starrRow和endRowIs the start and end points of intercepting line,They range fromcacheBlockSize 来控制.rowsThisPage Is to show the piece,dataIs the data returned is array format,lastRow是最后一行,当它为-1时,Module has been loaded,所以要判断data.length 是否小于endRow,If less than the end of the array of data,没数据了,This time we will take the last line is set to the length of the array.
经过上面的说明.我们弄清楚了getRow里面的逻辑,Now we come to realize scroll pages,代码太多,Everyone's scene may also be different,我就说一下思路.我们在vue定义startRow,endRow,pagesize,pageindex,And the back-end returneddata,I set is to return a request return100个数据,We request a data outside,把返回的数据赋值给data.设定pagesize=1,pageindex=100,startRow=0,endRow=10,截取的范围是10条,然后在getRow里面让this.startRow+=10,this.endRow+=10,this.pagesize++通过vueTwo-way binding principle to realizestartRow,endRow,pagesize动态变化,重点来了,当我们的endRow为100时,Triggered the judge
if (data.length <= endRow) {
if(data.length<100){
// This is a return to the insufficient data of100条了,Means the end of the back-end data
lastRow = data.length;
}else{
//When we the end of the first page scrolling,Let the page to add1,并进行请求,So we can get to the next page data,然后this.startRow=0,this.endRow=10Also be reset,So then sliding,The effect of the realized scrolling page
this.startRow=0
this.endRow=10
this.pagesize++
fetch('https://www.ag-grid.com/example-assets/olympic-winners.json')
.then((data) => this.data=data);
},
}
}
网站:https://www.ag-grid.com/vue-data-grid/infinite-scrolling/
官网示例
import 'ag-grid-community/styles/ag-grid.css';
import 'ag-grid-community/styles/ag-theme-alpine.css';
import {
AgGridVue } from 'ag-grid-vue';
import Vue from 'vue';
const VueExample = {
template: ` <div style="height: 100%"> <ag-grid-vue style="width: 100%; height: 100%;" class="ag-theme-alpine" :columnDefs="columnDefs" @grid-ready="onGridReady" :rowBuffer="rowBuffer" :rowSelection="rowSelection" :rowModelType="rowModelType" :cacheBlockSize="cacheBlockSize" :cacheOverflowSize="cacheOverflowSize" :maxConcurrentDatasourceRequests="maxConcurrentDatasourceRequests" :infiniteInitialRowCount="infiniteInitialRowCount" :maxBlocksInCache="maxBlocksInCache"></ag-grid-vue> </div> `,
components: {
'ag-grid-vue': AgGridVue,
},
data: function () {
return {
columnDefs: [
{
headerName: 'ID',
maxWidth: 100,
valueGetter: 'node.id',
cellRenderer: (params) => {
if (params.value !== undefined) {
return params.value;
} else {
return '<img src="https://www.ag-grid.com/example-assets/loading.gif">';
}
},
},
{
field: 'athlete', minWidth: 150 },
{
field: 'age' },
{
field: 'country', minWidth: 150 },
{
field: 'year' },
{
field: 'date', minWidth: 150 },
{
field: 'sport', minWidth: 150 },
{
field: 'gold' },
{
field: 'silver' },
{
field: 'bronze' },
{
field: 'total' },
],
gridApi: null,
columnApi: null,
defaultColDef: {
flex: 1,
resizable: true,
minWidth: 100,
},
rowBuffer: null,
rowSelection: null,
rowModelType: null,
cacheBlockSize: null,
cacheOverflowSize: null,
maxConcurrentDatasourceRequests: null,
infiniteInitialRowCount: null,
maxBlocksInCache: null,
};
},
created() {
this.rowBuffer = 0;
this.rowSelection = 'multiple';
this.rowModelType = 'infinite';
this.cacheBlockSize = 100;
this.cacheOverflowSize = 2;
this.maxConcurrentDatasourceRequests = 1;
this.infiniteInitialRowCount = 1000;
this.maxBlocksInCache = 10;
},
methods: {
onGridReady(params) {
this.gridApi = params.api;
this.gridColumnApi = params.columnApi;
const updateData = (data) => {
const dataSource = {
rowCount: undefined,
getRows: (params) => {
console.log(111)
// At this point in your code, you would call the server.
// To make the demo look real, wait for 500ms before returning
setTimeout(function () {
// take a slice of the total
const {
startRow,endRow } =params
const rowsThisPage = data.slice(startRow,endRow)
// const rowsThisPage = data.sstartRowlice(params.startRow, params.endRow);
// if on or after the last page, work out the last row.
let lastRow = -1;
if (data.length <= endRow) {
lastRow = data.length;
}
// call the success callback
params.successCallback(rowsThisPage, lastRow);
}, 500);
},
};
console.log(3,dataSource)
params.api.setDatasource(dataSource);
};
fetch('https://www.ag-grid.com/example-assets/olympic-winners.json')
.then((resp) => resp.json())
.then((data) => updateData(data));
},
},
};
new Vue({
el: '#app',
components: {
'my-component': VueExample,
},
});
Code word is not easy to order a great ball ball
边栏推荐
猜你喜欢
随机推荐
- Datax3.0+DataX-Web builds distributed visual ETL system
- [Popular Science] What basic knowledge do I need to learn to engage in Web3?
- Original Questions for Level 5 of China Electronics Society Youth Grade Examination
- [Cloud Native--Kubernetes] Configuration Management
- Use Specification and Example to implement dynamic conditional query cases
- JMeter集合点
- JMeter关联执行
- JMeter代理录制手机app
- The origin of the name, concave language -, and moral
- [面试篇]Mysql 索引 BTree 与 B+Tree 的区别
- I set the global mapping table prefix in yml, but the database does not recognize it
- Simulate the realization of strcpy function (including multiple optimization ideas)
- Script for reverse generation of entity class, query and other interface xml of MySQL database
- 快速学会文件操作模块
- js simulates the function of dynamically deleting messages
- How to improve the quality of articles without being "recommended and affected" by the post assistant
- CSDN official plug-in
- C语言 结构体
- 【leetcode】8. 字符串转换整数 (atoi)
- "Digital reconstruction system, CEO is the first step"
- how to jump higher
- No, no, no, it's 2022, you don't know the principle of Jmeter, right?
- 测试用例设计方法-场景法详解
- 一文3000字解析Pytest单元测试框架【保姆级教程】
- 2022-08-05:以下go语言代码输出什么?A:65, string;B:A, string;C:65, int;D:报错。
- Jetpack WorkManager 看这一篇就够了~
- 关于np.zeros()第三个参数:c代表与c语言类似,行优先;F代表列优先的记录
- 腾讯云点播上传视频文件解决路径问题
- Parameter ‘courseId‘ not found. Available parameters are [arg1, arg0, param1, para
- LeetCode——345. 反转字符串中的元音字母
- LeetCode——1047. 删除字符串中的所有相邻重复项
- 山石发声 | 做好安全运营,没有你想象的那么难
- bpe 中文tokens
- dalle2:hierarchical text-conditional image generation with clip
- qwqの科技flag
- 2022海亮SC游记
- 20220803模拟
- 代码签名证书可以解决软件被杀毒软件报毒提醒吗?
- 使用aggird组件实现下滑请求分页从而实现无限滚动的效果
- 代码签名证书多少钱?