首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NG2-智能表行索引

NG2-智能表行索引
EN

Stack Overflow用户
提问于 2018-08-01 15:33:02
回答 3查看 3.4K关注 0票数 1

我在我的angular项目中使用了ng2-smart-table,它的工作效果与预期一致。我只想知道如何在每一行中显示行号。如果有任何方法或解决办法,请建议。下面是我的数据设置和我的NG2智能表中的样本数据

代码语言:javascript
复制
settings2 = {
    columns: {
      id: {
        title: 'ID',
        filter: true,
      },
      name: {
        title: 'Fact',
        filter: true,
      },
      description: {
        title: 'Description',
        filter: true,
      },
    },
    actions: {
      add: false,
      edit: false,
      delete: false,
      custom: [
        {
          name: 'view',
          title: `<i class="ti-eye text-success m-r-10" data-target="#view"></i>`,
        },
        {
          name: 'edit',
          title: `<i class="ti-pencil text-info m-r-10" data-target="#update"></i>`,
        },
        {
          name: 'delete',
          title: `<i class="ti-trash text-danger m-r-10"></i>`
        },
      ]
    }
  }

数据-

代码语言:javascript
复制
[{
"id":  "770e6370-cf14-4a0a-b9db-0a6e99b5783b" ,
"list": [
{
"description":  "Coopentity" ,
"type":  "CO_OP"
} ,
{
"description":  "" ,
"type":  "FARM"
} ,
{
"description":  "" ,
"type":  "FACTORY"
} ,
{
"description":  "" ,
"type":  "AUDITING_FIRM"
}
] ,
"name":  "entity_types"
}]

HTML -

代码语言:javascript
复制
 <ng2-smart-table [settings]="settings2" [source]="facts" (custom)="onCustom($event)" class=""></ng2-smart-table>
EN

回答 3

Stack Overflow用户

发布于 2019-07-04 20:29:23

智能表设置中的

代码语言:javascript
复制
index:{
  title: 'sr_no',
  type: 'text',
  valuePrepareFunction: (value,row,cell) => {
    return cell.row.index;
   }
}
票数 1
EN

Stack Overflow用户

发布于 2019-09-24 17:49:12

如果假设component.ts正文中dataSource为:

代码语言:javascript
复制
source: LocalDataSource;

在您的列定义中:

代码语言:javascript
复制
valuePrepareFunction : (val,row,cell)=>{
   const pager = this.source.getPaging();
   const ret = (pager.page-1) * pager.perPage + cell.row.index+1;

   return ret;
}
票数 0
EN

Stack Overflow用户

发布于 2020-01-29 16:13:00

也许如果你想在打字稿中获得索引,也许这可以帮助你:

在html中

代码语言:javascript
复制
<ng2-smart-table #table [settings]="settings" [source]="source"></ng2-smart-table>

在打字稿中

代码语言:javascript
复制
@ViewChild('table', { static: false }) table;
getIndex(columnName: string) {
let index = 0;
  for (const column in this.table.columns) {
    if (column === columName) {
      console.log(index);
    }
  index++;
  }
}

希望这就是你要找的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51627727

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档