Giter Site home page Giter Site logo

irossimoline / angular4-material-table Goto Github PK

View Code? Open in Web Editor NEW
55.0 55.0 25.0 1.05 MB

Angular 4 table based on @angular/cdk table structure, to allow row insertion, edition, validation and deletion.

License: MIT License

TypeScript 96.62% JavaScript 3.38%

angular4-material-table's People

Contributors

angular-cli avatar blavenie avatar frankiepo avatar irossimoline avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

angular4-material-table's Issues

Which function to call for sending a put request to my server?

Please help!!
I was wondering which method to call or rather how do i send a put request which is implemented in BookService as a method called updateBook() which accept an array
I have tried to a demo on your existing demo here I keep getting error when trying to access datasourceSubject you see the error in the console of the demo.


// Stable Material table implementation.
export class BooksTableComponent implements onInit {
   dataSource: TableDataSource<Book>;
@Output() bookListChange = new EventEmitter<Book[]>();
   displayedColumns = ['title', 'author', 'publisher', 'publishedDate', 'isbn', 'price', 'actionsColumn'];

   constructor(private bookService: BookService, private bookValidator: ValidatorService) {}

   ngOnInit() {
     this.bookService.getBooks().subscribe(
       (data) => {
         this.dataSource = new TableDataSource<Book>(data, Book, this.bookValidator);
       }
     );
this.dataSource.datasourceSubject.subscribe(
      (data) => {
        this.bookListChange.emit(data);
        console.log(data);
      }
   }
 }

Conflict with rendere 3 in node_modules

I'm getting error when I run my project. Currently my angular version is 7.

ERROR in node_modules/@angular/core/src/render3/ng_dev_mode.d.ts(9,11): error TS2451: Cannot redeclare block-scoped variable 'ngDevMode'.
n
ode_modules/angular4-material-table/node_modules/@angular/core/src/render3/ng_dev_mode.d.ts(9,11): error TS2451: Cannot redeclare block-scoped variable 'ngDevMode'.

However after I deleting node_modules folder inside angular4-material-table folder which is in project's node_module, I could run without problem.

Repository License

The license for the published package on npmjs.com is MIT. Can you make the license on the github repository match that license? Thanks.

Can't bind to 'formControl' since it isn't a known property of 'input'.

Hello sir,

I try to implement your code in my project but getting errors like this , Can you please help to solve this problem . Thank you

Can't bind to 'formControl' since it isn't a known property of 'input'. ("
<mat-cell *matCellDef="let row">

<input [ERROR ->][formControl]="row.validator.controls['name']" [readonly]="!row.editing" placeholder="Name" [(ngModel"): ng:///AppModule/FormGenerationComponent.html@5:23
Can't bind to 'ngModel' since it isn't a known property of 'input'. (" <input [formControl]="row.validator.controls['name']" [readonly]="!row.editing" placeholder="Name" [ERROR ->][(ngModel)]="row.currentData.name" matInput>


"): ng:///AppModule/FormGenerationComponent.html@5:115
Can't bind to 'formControl' since it isn't a known property of 'input'. ("
<input [ERROR ->][formControl]="row.validator.controls['age']" type="number" placeholder="Age" [(ngModel)]="row.curren"): ng:///AppModule/FormGenerationComponent.html@13:23
Can't bind to 'ngModel' since it isn't a known property of 'input'. (" <input [formControl]="row.validator.controls['age']" type="number" placeholder="Age" [ERROR ->][(ngModel)]="row.currentData.age" matInput>


"): ng:///AppModule/FormGenerationComponent.html@13:101
No provider for NgControl ("
<mat-cell *matCellDef="let row">

[ERROR ->]<input [formControl]="row.validator.controls['name']" [readonly]="!row.editing" placeholder="Name" [("): ng:///AppModule/FormGenerationComponent.html@5:16
No provider for NgControl ("
[ERROR ->]<input [formControl]="row.validator.controls['age']" type="number" placeholder="Age" [(ngModel)]="row"): ng:///AppModule/FormGenerationComponent.html@13:16

error TS2416: Property 'connect' in type 'TableDataSource<T>' is not assignable to the same property in base type 'DataSource<TableElement<T>>'.

Hello

I get this error when I try to implement locally your example and I suppose it's because Angular 8 is not backward compatible with Angular 4.

Error Image

What is this error about?
Can you help me fix it?

Additional details:

npm install --save @angular/material @angular/cdk
npm install --save @angular/flex-layout
npm install --save hammerjs
npm install --save angular4-material-table
npm install --save rxjs

Warning message Ngmodel is getting deprecated

It seems that ngmodel will be removed on Angular7.
I tried to change the code to in order to support the new practices regarding FormGroup and FormControl. But the lines appear always in edit mode.

This is the snippet I have used:
<input matInput formControlName="row.validator.controls['name']" [readonly]="!row.editing" placeholder="Name" [value]="row.currentData.name">

Any thoughts about this?

image

Thanks!

Date picker edit field doesn't fit in the cell

Hi

I have a table where the editor shown is dependent on a type setting in another column
The issue i'm having is the cell doesn't fit in the calendar button for a calendar popup editor
I'm sure there is a simple css solution to this but I'm no css expert

(image of date editor active, you can see the calendar button which normally is at the end of the field is wrapped to a second row)

image

Extending TableDataSource

Hi,
First of all thanks for this great library, i have been using a normal material dataTable which uses an extended DataSource to make http requests (It's actually a socket but let's say http :) )
i have tried to use your component instead but it seems it can't conform exactly like a normal DataSource. I have made the connect and disconnect function with same structure as yours but still TsLint and angular-cli throws error on it.

Here is the error it throws on angular-cli:

Cannot redeclare block-scoped variable 'ngDevMode'.
node_modules/angular4-material-table/node_modules/@angular/core/src/render3/ng_dev_mode.d.ts(9,11): error TS2451: Cannot redeclare block-scoped variable 'ngDevMode'.
node_modules/angular4-material-table/node_modules/rxjs/internal/symbol/observable.d.ts(4,18): error TS2687: All declarations of 'observable' must have identical modifiers.
src/app/_shared/custom-data-source.ts(19,5): error TS2416: Property 'connect' in type 'CustomDataSource' is not assignable to the same property in base type 'TableDataSource<any>'.
  Type '() => Observable<TableElement<any>[]>' is not assignable to type '() => Observable<TableElement<any>[]>'. Two different types with this name exist, but they are unrelated.
    Type 'Observable<TableElement<any>[]>' is not assignable to type 'Observable<TableElement<any>[]>'. Two different types with this name exist, but they are unrelated.
      Types of property 'source' are incompatible.
        Type 'Observable<any>' is not assignable to type 'Observable<any>'. Two different types with this name exist, but they are unrelated.
          Types of property 'operator' are incompatible.
            Type 'Operator<any, any>' is not assignable to type 'Operator<any, any>'. Two different types with this name exist, but they are unrelated.
              Types of property 'call' are incompatible.
                Type '(subscriber: Subscriber<any>, source: any) => TeardownLogic' is not assignable to type '(subscriber: Subscriber<any>, source: any) => TeardownLogic'. Two different types with this name exist, but they are unrelated.
                  Types of parameters 'subscriber' and 'subscriber' are incompatible.
                    Type 'Subscriber<any>' is not assignable to type 'Subscriber<any>'. Two different types with this name exist, but they are unrelated.
                      Property 'isStopped' is protected but type 'Subscriber<T>' is not a class derived from 'Subscriber<T>'.

here is my datasource class extended from your TableDataSource:

export class CustomDataSource implements TableDataSource<any> {

    private rowsObject = new BehaviorSubject<any[]>([]);
    private loadingSubject = new BehaviorSubject<boolean>(false);
    private countSubject = new BehaviorSubject<number>(0);

    public loading$ = this.loadingSubject.asObservable();
    public count$ = this.countSubject.asObservable();

    constructor(private socketSerivce: SocketService) {}

    connect(): Observable<TableElement<any>[]> {
        return this.rowsObject.asObservable();
    }

    disconnect(): void {
        this.rowsObject.complete();
        this.loadingSubject.complete();
    }

    getRows(tableName, filers, sort, page, pageSize, fullTextFields, fullTextValue) {

        this.loadingSubject.next(true);

        this.socketSerivce.getRows(tableName, filers, sort, page, pageSize, fullTextFields, fullTextValue).pipe(
            catchError(() => of([])),
            finalize(() => {})
        )
        .subscribe(lessons => {
            this.loadingSubject.next(false);
            this.rowsObject.next(lessons);
            if (lessons.length > 0) {
                this.countSubject.next(lessons[0].count);
            }
        });
    }
}

Expandable row to display a child table

In efforts to use the material table to fit my needs I am wondering if there's any possibility of inserting a an expansion panel containing a mat-table inside of another mat-table or mat-cell (Parent-Child situation). I've been trying to get it to work but nothing outside of the data-bound form control shows up (the panel does not show at all.) Was the cdk-table or material-table design meant to be that flexible?

How to use this code with reactive forms and form Arrays ?

Hello,
I loved the code, it will be really helpful if you can guide me on how to implement this kind of table with reactive forms and FormArray.
let's say that the below method is responsible for creating the form

createForm(){
 this.entryForm = this.formBuilder.group({
        date: ['', [Validators.required]],
        notes: [''],
        items: this.initItems()
      
      });
}

I need to manage the Items through an editable table, at the beginning the table must have two empty rows:

 initItems(){
    var formArray = this.formBuilder.array([]);
 
    for(let i=0 ; i< 2 ; i++){
      formArray.push(this.formBuilder.group({
        name: ['', [Validators.required]],
        age: ['', [Validators.required]],
      }));
    }
    
  return formArray;
  }

The Html markup of the table should be drawn according to the data of the items formArray.
to add a row to the table, I need to add a row to the formArray first:

addNewItem(name: string , age: number){
 var controls = <FormArray>this.entryForm.controls['items'];
  var formGroup= this.fb.group({
      name: [name, [Validators.required]],
       age: [age, [Validators.required]],
    });
    controls.push( formGroup);
}

the same for edit and remove, I need to remove the row form the FormArray.
I just can't Imagine how can I link this code to yours?

When can TableElement.currentData be undefined?

I have strictNullChecks enabled, and I have the following code:

// html
<button (click)="delete(row)">

// ts
delete(row: TableElement<X>) {
  // do some business with one of the properties of currentData: for example logging it:
  console.log(row.currentData.someProperty)
  row.delete()
}

When I compile it, I get this error:

error TS2532: Object is possibly 'undefined'

That's because currentData is optional in TableElement class, so it could possibly be undefined and I can't access someProperty on undefined.

My question: at what cases would currentData be undefined? I'm bewildered because originalData isn't optional. Can currentData just be a required property like originalData?

Thanks!

Upgrade to angular 7 to angular 8

Hello,
I made the upgrade angular 7 to angular 8 on my project.
And the error is occurring when the AOT compile at the production mode:

ERROR in ..\angular4-material-table\src\app.module.ts(4,2): Error during template compile of 'AppModule'
Function calls are not supported in decorators but 'ɵmakeDecorator' was called in 'NgModule'
'NgModule' calls 'ɵmakeDecorator'.

Please, can you help?

npm install --save angular4-material-table

I got the following error when I tried to install:

npm ERR! code EINVALIDPACKAGENAME
npm ERR! Invalid package name "@angular/cdk/collections": name can only contain URL-friendly characters

Issue with node_modules with in angular4-material-table package

I'm facing Issue after installing angular4-material-table NPM module.
After research, I found like my solution already contains @angular package with core, common and forms
image

Inside the Angular4-material-table module, Again we have Node_modules with the core, common and forms
image

Error Im getting:
image

Package.json
image

vulnerabilities in npm Package

I have tried installing the package, It has displayed on installation complete.
found 15 vulnerabilities (4 low, 5 moderate, 6 high)

Setting default values in FormControl

Hi,

I am trying to set a default value for a cell when creating a new row, but for some reason i cant make it work... any help will be appreciated.

How to get the current data in TableDataSource?

Currently there's no public attribute for us to get the current data in TableDataSource instance, right?
I check the source code of TableDataSource, it seems the data is stored in rowsSubject, could we change the rowsSubject to a public attribute? so that we can deal the logic with data rows in typescript files.

Example of saving changes to an API

Can you provide an example of data changes being saved via Put/Post/Delete? Based on the demo I can make changes in the form but those changes aren't permanent.
As a newbie this table looks great and is pretty easy to integrate when it comes to initially populating the table via Http(Get). However, being a newbie ... if I need to permanently save my changes (new, edit or delete) how would can I call my service? Do I have to extend TableDataSource or can it be done somewhere in the button (click) ?

TableDataSource should extend MatTableDataSource instead of DataSource

Hi irossimoline,

First of all, what you've developed is very cool and useful.
I think it could even be better with few changes.
TableDataSource should extend MatTableDataSource instead of DataSource. Like that, TableDataSource would inherited the filter and sort methods which are provided OOTB by Material.

How to use a mat-autocomplete

Is it possible to use a mat-autocomplete in a cell in the table?
In addition, then typing in the autocomplete component the filtering should be done using a http call, like they do in this example: https://stackblitz.com/edit/angular-nku8fq?file=app/app.component.ts

The hardest thing for me to wrap my head around is how to react to changes to the autocomplete input field and do the filtering, like they do in the example I linked to:

this.filteredOptions = this.myControl.valueChanges
      .pipe(
        startWith(null),
        debounceTime(200),
        distinctUntilChanged(),
        switchMap(val => {
          return this.filter(val || '');
        })
      );

How do I get hold of the form control for each row and subscribe to its changes?
Any suggestions?

Build errors after updating to 0.8.0

Good day.

I have updated my project to Angular 8 and also the angular4-material-table which is awesome to 0.8.0.

I have a problem though that when I try and build my project or the table on its own I get a lot of errors. I am no js or Angular expert and cannot seem to figure out why this happens.

Attached is the output from the build.
angular4-material-table-build-error.log

Cannot overwrite row.currentData

Hi,
I'm checking if any of properties in object contains '' (empty string) and i'm trying to override it with null value.

for (let key in row.currentData) {
  if ((!row.currentData[key]) || (row.currentData[key] && (row.currentData[key].toString().trim() === '') {
    row.currentData[key] = null;
  }
}

but after all, when I debug row.currentData selected property still has value: '' instead of null. What's wrong?

createNew function

hi
while creating new item, I want to see added empty-data row at the top of table instead of buttom of it.
Is there any config setting to do this or should I change source code. If source code should be changed, How can I change?

TypeError: undefined is not an object (evaluating 'this.dataKeys.reduce')

Hi!
In the TableDataSource class / createNewObject function I get this error when I try to create a new element: ERROR - TypeError: undefined is not an object (evaluating 'this.dataKeys.reduce') wether by invoking (click)="dataSource.createNew()" in the view or when calling's the this.dataSource.createNew();function in the component. I'm not trying to innovate for the moment. Just trying to import StackBlitz's code in my app.

When I do a console.log(this.dataConstructor);and a console.log(this.dataKeys);inside the createNewObject()function both are undefined.

Any idea on how to solve this?

Nested Properties for sortingDataAccessor

Due to some inflexibility in the data I was using I was investigating a way to bind mat-sort-header to a nested property in the data structure. I ended up writing a custom function to replace the sortingDataAccessor in MatTableDataSource in order to facilitate this. It's written in a generic way so I was thinking I'd get some feedback on the idea first and then create a PR for the change if it sounds helpful.

Not an Issue - HTTP interceptor Conflict with keycloak-angular

Hi,

Thanks for all great effort in this nice plugin. I am using this plugin with Angular 6.

One observation is that when this plugin having some conflict with with keycloak-angular plugin (https://github.com/mauriciovigolo/keycloak-angular).
keycloak-angular plugin supposed to include Authorization header with Bearer + token using http interceptor. When this plugin is included in my project, It's not doing that any more. I am still investigating to find root cause of conflict. However, it would be helpful to share if this plugin uses the http interceptor and pointer in source code.

Thanks,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.