【问题标题】:How to write custom sort logic on sort column event in ng2-smart-table如何在 ng2-smart-table 中的排序列事件上编写自定义排序逻辑
【发布时间】:2019-04-10 14:57:25
【问题描述】:

我正在寻找在 ng2-smart-table 上执行的排序事件。关注https://akveo.github.io/ng2-smart-table/#/documentation,我看到一堆暴露的事件,如 rowSelect、mouseover 等,但我没有看到库发布/发出的排序事件。我正在考虑更改 Ng2SmartTableComponent 并在内部调用 (sort) 时发出一个事件。我想知道是否有人已经这样做了,或者是否有我可以依赖的 hack。

【问题讨论】:

    标签: ng2-smart-table


    【解决方案1】:

    ng2-smart-table 中排序的来源显示在 GitHub (link to code) 上。

    如果您想更改 compare-Function(默认使用),您可以在 ng2-smart-table-configuration 中添加自己的自定义函数:

    columns: {
        group_name: {
            title: 'Groupname',
            compareFunction(direction: any, a: any, b: any) => {
               //your code
            }
        }
    }
    

    【讨论】:

      【解决方案2】:

      我正在寻找一个事件来对我的数据进行远程排序,我找到了解决方案。我也有一些页面更改事件(远程分页)的逻辑。这对我有用。

      ts

      source: LocalDataSource = new LocalDataSource();
      
      ngOnInit() {
        this.source.onChanged().subscribe((change) => {
          if (change.action === 'sort') {
            this.sortingChange(change.sort);
          }
          else if (change.action === 'page') {
            this.pageChange(change.paging.page);
          }
        });
      }
      

      html

      <ng2-smart-table [settings]="settings" [source]="source"></ng2-smart-table>
      

      此解决方案不会取代自定义逻辑,但它可能会帮助您解决问题。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-06-02
        • 2018-05-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-11-23
        • 2023-04-02
        • 2018-08-10
        相关资源
        最近更新 更多