Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
55
I am looking for a way to add columns in the igx grid table?
posted

https://stackblitz.com/edit/angular-1v1k8m?file=src%2Fapp%2Fgrid%2Fgrid-paging-sample%2Fgrid-paging-sample.component.html 

If I follow the above method, it works for 1 time. But recently an error occurred. The error is encountered when I successfully add the column and then edit the newly created cells, it gives an error.

Who knows help me with. Tks you!

Parents Reply
  • 55
    Verified Answer
    Offline posted in reply to Bozhidara Pachilova

    Hi Bozhidara Pachilova!

    cond.zip

    The file above contains the code I'm using.

    <igx-grid [hideRowSelectors]="true" #grid1 [data]="rowData" [height]="null" primaryKey="title" displayDensity="compact" [clipboardOptions]="copyOptions" paste-handler
              (onDataProcessed)="dataPasted($event, grid1, 1)"
              (cellEditExit)="cellEditExit($event, 1)"
              (gridKeydown)="customKeydown($event, grid1)"
              (keydown)="handleKeyDownBoardEvent($event, grid1)"
              (keyup)="handleKeyUpBoardEvent($event, grid1)"
              (cellEditEnter)="cellEditEnter($event, rowData)"
              (cellClick)="checkClickFluidType($event)"
              (selected)="setCellSelection($event, grid1, 'onSelection')"
              (rangeSelected)="setCellSelection($event, grid1, 'onRangeSelection')"
              (activeNodeChange)="onActiveNodeChange($event, grid1)"
    >
      <igx-column field="title" header="項目名" [width]="widthTitle" [pinned]="true" [headerClasses]="'text-center'" [cellClasses]="cellCls2">
      </igx-column>
      <igx-column *ngFor="let c of columns" [field]="'no'+c" [header]="'No.'+c" [width]="'130px'" [editable]="true" [headerClasses]="'text-center pd0'" [cellClasses]="cellClsDirtyCheck"></igx-column>
    </igx-grid>

      addTab() {
        this.columns.push(this.columns.length + 1);
        this.rowData.map(row => {
          if (row.field === 'WITH_FIN_A' || row.field === 'WITH_FIN_B') {
            return row['no'+this.columns.length] = true;
          } else {
            return row['no'+this.columns.length] = '';
          }
        };
      }

    related html and ts files.

    First I have column number from no1->no16.

    When I click "追加" button (add column) it generates no17.

    Here I click to edit the data of column no17, I am getting the above error.

    Note: Column no17 is being generated by the library after I push to add an element to the columns array.

Children