-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🚨🚨🚨🚨 Resizing columns when columns are created as classes breaks 🚨🚨🚨🚨 #666
Comments
@arlowhite - I believe this is a regression of your PR today. Can you investigatE? |
@amcdnl ok, I'll take a look at it and try to submit a fix tomorrow. |
@leolorenzoluis I get a 404 from http://run.plnkr.co/qY8q97gZkSeZ7Kvv/ Is your Plunker example still online? |
@arlowhite I don't know what happened to plunker, but if you expand the details I attached and use the demo app under |
@leolorenzoluis I don't get an error with your code. I also tried instances of Test and it worked.
Does 8.0.0 and the newest version of Angular work for you? |
@leolorenzoluis I don't see how |
@arlowhite Ah yes I changed the template in HTML, the breakIt function is attached inside a column header template. You can use |
@arlowhite Here's a plunker. http://plnkr.co/edit/J3qsdqFQUmWvVVzPwDR1?p=preview Open the web debug tools and watch the console. Type something under column name's input control, then resize. Notice that it has the old value of the query. Just in case plunkr disappears again. Here's the code:
|
Confirmed. Resize seems to do a clone of the column object. You can work around this by passing in the column as an argument within the template and only using that parameter in your code: This does seem like a bug that should be fixed. |
@amcdnl the shallow-clone happens here: https://github.com/swimlane/ngx-datatable/blob/master/src/components/datatable.component.ts#L921 I'm not going to attempt a fix because I don't know enough about this code or the need for Object.assign here. |
Yeah that's what I thought. I just "re-attach" the binding the column and find it on my backing @amcdnl Just like arlow, I don't know enough about the code, but I can sense the functional programming principle here that it's trying to apply immutability, but why? As a consumer of the API, I would expect that if the |
I'm submitting a ... (check one with "x")
Current behavior
When resizing the column when columns are created as an instance of a class, then it breaks the table and the binding value still has the previous value. Here is the ff error:
If I change it to like this then it doesn't break. But it loses the binding. It shows the previous value of the original object prior to resizing the column.
@ViewChild('editTmpl') editTmpl: TemplateRef;
@ViewChild('hdrTpl') hdrTpl: TemplateRef;
rows = [];
columns = [];
constructor() {
this.fetch((data) => {
this.rows = data.splice(0, 5);
});
}
ngOnInit() {
let a = {};
a['cellTemplate'] = this.editTmpl;
a['headerTemplate'] = this.hdrTpl;
a['name'] = 'Gender';
a['giveme'] = () => {
console.log("blah");
}
a['breakIt'] = () => { if (b['query']) return true; return false };
let b = {};
b['cellTemplate'] = this.editTmpl;
b['headerTemplate'] = this.hdrTpl;
b['name'] = 'Name';
b['giveme'] = () => {
console.log("blah");
}
b['breakIt'] = () => { if (b['query']) return true; return false };
this.columns = [a,
b];
}
fetch(cb) {
const req = new XMLHttpRequest();
req.open('GET',
assets/data/company.json
);}
blah() {
console.log(this.columns);
}
}
export class Test {
name: string;
cellTemplate: TemplateRef;
headerTemplate: TemplateRef;
query: string;
giveme() {
console.log(typeof (this));
console.log(this.query);
}
breakIt() {
if (this.query) return true; return false;
}
}
Expected behavior
It should not break.
Reproduction of the problem
http://run.plnkr.co/qY8q97gZkSeZ7Kvv/
Please tell us about your environment:
Windows 10, Node version 6.10.0
Table version: 0.7.1
Angular version: 4.0.x
Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]
All
Language: [Typescript 2.2.1]
The text was updated successfully, but these errors were encountered: