akveo / ng2-smart-table

Angular Smart Data Table component
https://akveo.github.io/ng2-smart-table/
MIT License
1.63k stars 878 forks source link

Issue with multiselect and add new in the latest version. #412

Open EtiAggarwal opened 7 years ago

EtiAggarwal commented 7 years ago

I created a table that has add new and multiselect options, but when add new is clicked, the columns shift to left. I have attached screenshots for reference. image

columns shift to left image

I am using angular 4

karangarg45 commented 7 years ago

has this been fixed? or any workaround?

EtiAggarwal commented 7 years ago

I had to edit the row template. It is missing the checkbox tag

kohanevich85 commented 7 years ago

that's because of this [ng2-st-thead-form-row] component has issue in template <td *ngIf=""></td> but should be: <td *ngIf="grid.isMultiSelectVisible()"></td> I have some workaround, I manipulated to DOM directly but it's bad solution, append first child <td/> to <tr>

sendruck commented 7 years ago

@kohanevich85 can you please share the code of your temporary workaround in case it's will not merge

kohanevich85 commented 7 years ago

Here is an example of fix. It's direct DOM manipulating there is bad practice, but it works for me. I think these magic numbers should work for you as well.

constructor(private elRef: ElementRef, private _renderer: Renderer2) {

ngAfterViewChecked() { let firstRow = 2; let columnOffset = 4; if (this.elRef.nativeElement.querySelector('.ng2-smart-action-add-create')) { let td = this._renderer.createElement("td"); let tr = this.elRef.nativeElement.getElementsByTagName('tr')[firstRow]; let refChild = tr.childNodes[columnOffset]; if (refChild.className === 'ng2-smart-actions') { this._renderer.insertBefore(tr, td, refChild); } } }

sendruck commented 7 years ago

@kohanevich85 Where did you implement this code?

sendruck commented 7 years ago

Is it ok to implement hook in the constructor, cos it didn't work for me((

kohanevich85 commented 7 years ago

in this case it doesn't matter because of direct DOM manipulation and on event after view checked (ngAfterViewChecked). This code just should run. I used this code in component which include smart-table component.

kohanevich85 commented 7 years ago

constructor is not appropriate hook for this try to use ngAfterViewChecked()

sendruck commented 7 years ago

Thanks, I didnt use checkboxes, so there is no more problem for me