jps
jps

Reputation: 1

How to pass column of clicked cell to custom renderer

In ng2-smart-table that is rendering a custom component, when a cell is clicked the value of the cell is passed into the custom component but the column field Id is not

Upvotes: 0

Views: 246

Answers (1)

Sandeep
Sandeep

Reputation: 569

If you are looking for row information like row id or any other information on the column click then you can use the following steps

Define static variable static isColumnNameClick= false;

In HTML template

 <ng2-smart-table [settings]="settings" [source]="source"(userRowSelect) = "selectDataRow($event)"> </ng2-smart-table>

In setting, you can provide the following information

columns: {
  columnName: {
    type: 'custom',
    title: 'Column Name',
    renderComponent: ChildComponent,
    onComponentInitFunction(instance) {
    instance.nextAction.subscribe(row => CurrentComponent.isColumnNameClick = true);
    }
  }

}

Finally, in selectDataRow($event) function, you can check

selectDataRow(event) {
         if(CurrentComponent.isColumnNameClick) {
             CurrentComponent.isColumnNameClick = false;
              //access other row attributes using
               const id= event.data.id 
        }
}

Upvotes: 1

Related Questions