角度数据表 - 在动态列表

时间:2017-01-11 19:55:37

标签: angularjs datatables

我有一个带有可变列数的数据表,我需要向其添加行。

这就是我设置列的方式:

var columns = getColumnsName();
columns.forEach(function(column, index){
    dtColumns.push(DTColumnBuilder.newColumn(index).withTitle(column));
});

这仅适用于我未在<tr>内放置<tbody>的情况。如果我在<tr>内放置<tbody>,则会出现以下错误:

TypeError: Cannot read property 'length' of undefined
    at _fnGetRowElements (jquery.dataTables.js:3021)
    at HTMLTableRowElement.<anonymous> (jquery.dataTables.js:2428)
    at jquery.js:144
    at Function.map (jquery.js:467)
    at jQuery.fn.init.map (jquery.js:143)
    at _fnAddTr (jquery.dataTables.js:2427)
    at loadedInit (jquery.dataTables.js:1307)
    at HTMLTableElement.<anonymous> (jquery.dataTables.js:1332)
    at Function.each (jquery.js:374)
    at jQuery.fn.init.each (jquery.js:139)

请注意,如果我无法添加<tr>,我就无法在ng-repeat内放置<tbody>来重复我的数据。

我的内部<tr> <tbody>内部<td>内部<td>内容不足<tr>,似乎我收到了上述错误。假设我知道我有多少列并将<table dt-options="ctrl.dtOptions" dt-columns="ctrl.dtColumns" dt-column-defs="ctrl.dtColumnDefs" datatable="ng"> <thead></thead> <tbody></tbody> </table> 的确切数字放在using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace HotelWPF { public class ReservationVM : INotifyPropertyChanged { public Reservation reservation = new Reservation(); private string SecretaryName; private int RoomNumber; private string ReservationType; private DateTime ReservationDate; public string SecretaryName1 { get { return SecretaryName; } set { SetProperty(ref SecretaryName, value); } } public int RoomNumber1 { get { return RoomNumber; } set { SetProperty(ref RoomNumber, value); } } public string ReservationType1 { get { return ReservationType; } set { SetProperty(ref ReservationType, value); } } public DateTime ReservationDate1 { get { return ReservationDate; } set { SetProperty(ref ReservationDate, value); } } public void SetProperty<T>(ref T store, T value, [CallerMemberName] string name = null) { store = value; if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedArgs(name)); } } } 内,我不会收到此错误...

在这种情况下如何向表中添加行?

修改

正如所提出的,这里是HTML:

PropertyChanged doesn't exist in current context.

1 个答案:

答案 0 :(得分:1)

注入$ timeout后请尝试以下操作。

    $timeout(function(){

      var columns = getColumnsName();
      columns.forEach(function(column, index){
         dtColumns.push(DTColumnBuilder.newColumn(index).withTitle(column));
      });
    });