简体   繁体   English

ng2-smart-table 在滚动时加载数据

[英]ng2-smart-table load data on scroll

i want to load data on scroll.我想在滚动上加载数据。 scroll is applied ng-card.滚动应用 ng-card。

 <nb-card> <nb-card-body class="patientInfoStyle"> <ng2-smart-table [settings]="settings" [source]="source" (deleteConfirm)="onDeleteConfirm($event)"> </ng2-smart-table> </nb-card-body> </nb-card>

Thanks in advance.提前致谢。

You may do this easily using ngx-infinite scroll .您可以使用ngx-infinite scroll轻松完成此操作。

There is also an interest solution when it comes to image lazy loading.当涉及到图像延迟加载时,还有一个有趣的解决方案。 Follow this按照这个

This is not exactly the answer you were looking for but you can do the following:这不完全是您要寻找的答案,但您可以执行以下操作:

  • open github account开通github账号
  • go to ng2-smart-table git and fork to your repository转到 ng2-smart-table git 并 fork 到您的存储库
  • checkout library using the provided link using git clone使用提供的链接使用 git clone 结帐库
  • add infinite scroll using any library of your choosing (ngx-infinite scroll, angular material, etc.)使用您选择的任何库(ngx-infinite scroll、angular material 等)添加无限滚动
  • you can follow this guide in order to package your library to github and use it from package json in your project.您可以按照本指南将库打包到 github 并从项目中的 json 包中使用它。

In my case I used Angular Material cdk .就我而言,我使用了Angular Material cdk In order to use it with table in the library do the following:为了将它与库中的表一起使用,请执行以下操作:

  • wrap external table element with cdk用 cdk 包裹外部表格元素
  • in the tbody component replace * ngFor on 'tr' element with * cdkVirtualFortbody组件中用* cdkVirtualFor替换 'tr' 元素上的 * ngFor

The code written by the author has good practices and easy to read.作者编写的代码实践良好,易于阅读。 doing it yourself is not too difficult.自己做并不太难。 Also by doing above you can repeat this method with any open source libraries此外,通过执行上述操作,您可以使用任何开源库重复此方法

I followed @olNoy advise and I created an alpha version of ng2-smart-table with scrolling of the body using angular-cdk scrolling.我按照@olNoy 的建议创建了 ng2-smart-table 的 alpha 版本,并使用 angular-cdk 滚动来滚动主体。

You could find it at https://github.com/andreatoppan/ng2-smart-table it is quite rude but I wanted to share if someone is interested, as it is working in my case.你可以在https://github.com/andreatoppan/ng2-smart-table 上找到它,这很粗鲁,但如果有人感兴趣,我想分享一下,因为它在我的情况下有效。

I treated the head and the body as 2 different tables, placing a cdk-virtual-scroll-viewport outside the tbody.我将头部和身体视为 2 个不同的表,在 tbody 外放置了一个 cdk-virtual-scroll-viewport。 This way the head will remain in place and the body could scroll over.这样头部将保持原位,身体可以滚动。 The drawback of this approach is that the head and body column will be different, this is why I placed another head inside the second table and I created some not optimised functions to adjust the columns size in the component.这种方法的缺点是 head 和 body 列会不同,这就是为什么我在第二个表中放置了另一个 head 并创建了一些未优化的函数来调整组件中的列大小。 If you find it useful you could expand or fix at your wish.如果您发现它有用,您可以根据需要进行扩展或修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM