0

I am trying to add custom action "Copy" in Ng2SmartTable Grid. I am facing issue with click event handler of custom action. There are 3 buttons in grid Edit,Delete,Copy. Edit ,Delete is working fine. But 'Copy' method is not getting fired onclick of copy button.

Grid.component.html code

  <ng2-smart-table [settings]="settings" (custom)="onCustom($event)" [source]="source" (edit)="onEdit($event)" (delete)="onDelete($event)"></ng2-smart-table>

OnEdit ,OnDelete working fine But OnCustom not working.

Grid.component.ts file code for settings for ng2smarttable.

  mode: 'external',
    actions: {
        add: false,
       custom: [{
            name: 'copy', title: 'Copy'
        }]
    },

onCustom method not working at all.

1 Answers1

1

There must be an issue with the function in your component, the code you have shared in your question is setup correctly and works in this stackblitz.

Please note: when the copy button is clicked the event is passed to the onCustom function in the app.component.ts and logs the event in the console.

https://stackblitz.com/edit/smarttable-e8gqql?embed=1&file=app/app.component.ts

Marshal
  • 10,499
  • 2
  • 34
  • 53
  • Marshal Actually I have set debugger inside onCustom method this method is not getting fired. – Bhupinder Rajput Oct 13 '18 at 15:35
  • Please share your component code showing the onCustom method. If this is indeed setup correctly then the next logical step would be to see what version of smarrtable you are using, possibly need to upgrade and or review for possible bug. The version in the stackblitz works as expected. – Marshal Oct 13 '18 at 15:37
  • Here is link to the source for the custom.component.ts logic in the ng2-smart-table source. If you do suspect a bug, I would start by comparing your version in your node_modules folder to this to make sure they match. https://github.com/akveo/ng2-smart-table/blob/master/src/ng2-smart-table/components/tbody/cells/custom.component.ts – Marshal Oct 13 '18 at 15:41
  • Marshal I am using "ng2-smart-table": "^1.3.3" in package.json – Bhupinder Rajput Oct 13 '18 at 16:25
  • On stackblitz link custom button action working fine but I dont know why its not working in my component.ts file – Bhupinder Rajput Oct 13 '18 at 16:30
  • 1
    Stackblitz was using 1.2.2, I went ahead and upgraded it to "ng2-smart-table": "^1.3.5" and custom event still working in stackblitz. I do not believe this to be a version issue. There seems to be something specific to your environment, just not sure what it is without more sample code. – Marshal Oct 13 '18 at 16:37
  • I have copied datasource from stackblitz and paste in my component.ts file even then copy button event handler not getting fired. When I am inspecting the copy button class is different Copy In stackblitz copy button class is Copy – Bhupinder Rajput Oct 13 '18 at 17:07
  • animations not able to call copy event handler – Bhupinder Rajput Oct 13 '18 at 17:39
  • Marshal I found reason for problem , Actually BrowserAnimationsModule npm is conflicting with ng2 smart table thats why custom button event handler is not working . As I commented Animation module package now copy event handler is working . Thanks for the help Marshal. – Bhupinder Rajput Oct 14 '18 at 08:22