【问题标题】:Angular Datatable >> How to get total number of rows and sum of the all amount valuesAngular Datatable >> 如何获取总行数和所有金额值的总和
【发布时间】:2020-12-05 11:07:26
【问题描述】:

Angular Datatable >> 如何获取总行数和所有金额值的总和。需要获取表格的总行数。我尝试使用下表并仅获取第一页记录。请建议我如何get total number of records across all pages 并需要获得sum of the total records values。我试过下面的代码,

getTotalAmount(){
   let amountValues="";
    let rowCount = $("table > tbody").children().length;
    console.log("rowCount ::: " + rowCount);
    for(var i=0;i<rowCount;i++){
      if(this.persons[i].firstName === 'Superman' && this.persons[i].index != '')
        console.log(this.persons[i].index);
        amountValues += parseFloat(this.persons[i].enteredDebit);
    }
    console.log("amountValues >>>>>>>" + amountValues);
  }

Working Stackblitz

【问题讨论】:

  • this.personas.length 包含表中所有可能的行,因为您在 html 中循环此数组。对于价值观,你是什么意思?您获取的 json 返回 Id、Name 和 LastName 的数据集。
  • 其实我的问题是,我只能访问显示页面记录,我无法访问所有页面。
  • 我正在尝试获取“超人”的名字的所有金额值的总和(跨所有页面)

标签: javascript jquery angular datatables angular-datatables


【解决方案1】:

请查找更新后的代码。你必须使用 people[i].id 而不是 index。

https://stackblitz.com/edit/angular-datatables-gitter-zbcrwx?file=app/app.component.ts

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-31
    相关资源
    最近更新 更多