hjalmers / angular-generic-table

A generic table for Angular 2+. Generic table uses standard markup for tables ie. table, tr and td elements etc. and has support for expanding rows, global search, filters, sorting, pagination, export to CSV, column clicks, custom column rendering, custom export values.
https://hjalmers.github.io/angular-generic-table/
MIT License
104 stars 55 forks source link

Expand row on click #186

Closed Crash1988 closed 6 years ago

Crash1988 commented 6 years ago

Hi, i have a generic table with an CustomComponent but i want to expand the row not just when click on the field, also i want expand the row when they click in the entire row so i am calling the triger but i dont know how to call the toggleCollapse function. when i run the below code i get this error:

No component factory found for undefined. Did you add it to @NgModule.entryComponents?

<generic-table [gtClasses]="'table-hover'" #myTable [gtSettings]="configObject.settings" [gtFields]="configObject.fields" [(gtData)]="configObject.data" [gtInfo]="configObject.info" (gtEvent)="trigger($event)" [gtOptions]="{rowSelectionAllowMultiple: false, numberOfRows:20,highlightSearch:true, lazyLoad:true, rowSelection:true}"></generic-table>
  <div class="text-center">
    <gt-pagination [gtClasses]="'justify-content-center'" [genericTable]="myTable"></gt-pagination>
  </div>

public trigger = function ($event) {
    switch ($event.name) {     
      case 'gt-row-select':
        this.myTable.toggleCollapse($event.value.changedRow, CustomComponent);   
        break;
      case 'gt-row-deselect':
        this.myTable.toggleCollapse($event.value.changedRow,  CustomComponent );
        break;
      default:
        //console.log($event);
        break;
    }

  }; 
hjalmers commented 6 years ago

Hi @Crash1988, I'm going to add this as a feature request because I think it would be nice to have the option to do something on row click too. However this workaround should work and I've actually used it myself in some projects although not together with toggleCollapse. I realized toggleCollapse isn't documented in the wiki and there's a ni issue in how you're calling it. The second parameter should be an object like this:

{
  component: CustomComponent, // your component (must be added to entry components)
  data: someData // optional property for passing data to the component (row is passed by default)
}

Give it a try and let me know if it works for you:)

Crash1988 commented 6 years ago

Hi @hjalmers , thanks for the help, now is working perfectly, i just needed the structure, please let me know how i can help and contribute to this project, thanks again.

this.myTable.toggleCollapse($event.value.changedRow, { component:CustomComponent, data:[] });

Crash1988 commented 6 years ago

hi @hjalmers, i forked this repo so i want to collaborate but i did a fork, then i downloaded with git clone, after that i did npm install but then i have an issue so i executed npm install @angular-generic-table/core --save that solved that problem, now if i try ng build i get this error... capture

do you have any idea how i can fix that?

hjalmers commented 6 years ago

Great:) I have some ideas together with some co-workers of what we would like to do and some changes that we probably would want to make for a v5 release and help is always welcome:) One thing is actually restructuring the project and publish to npm using ng-packagr. But I think you should be able to run it locally if you run npm start.