【问题标题】:How to add static data columns in dataTable existing columns如何在dataTable现有列中添加静态数据列
【发布时间】:2021-05-14 10:46:50
【问题描述】:

有像 API 这样的要求提供很少的数据列,我需要添加一些静态数据列。有什么方法可以添加一些动态传递的列,例如{ data: this.test1 },{ data: this.test2 }。我尝试添加两列,但无法获取数据,得到空白单元格。

  constructor(private http: HttpClient) {}
   public test1 =123;
   public test2 =234;

初始化:

this.dtOptions = {
  pagingType: "full_numbers",
  pageLength: 10,
  scrollCollapse: true,
  processing: true,
  destroy: true,
  scrollY:'50vh',
  columns: [
    { title: '<input type="checkbox" />' },
    { data: "index" },
    { data: "firstname" },
    { data: "lastname" },
    { data: this.test1 },
    { data: this.test2 }
  ],

Stackblitz

【问题讨论】:

    标签: jquery angular datatables angular-datatables


    【解决方案1】:

    您可以将data 设置为null,然后使用defaultContent 选项。

    列定义中的硬编码:

    { title: "Hard-Coded Data", data: null, defaultContent: "foo" }
    

    类似,但使用 JavaScript 变量 - 例如,var bar = 'baz';

    { title: "Hard-Coded Data", data: null, defaultContent: bar }
    

    【讨论】:

      猜你喜欢
      • 2015-08-26
      • 1970-01-01
      • 2015-08-31
      • 2021-01-22
      • 2021-03-28
      • 1970-01-01
      • 2020-10-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多