-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
ui-grid-row-edit bug #1694
Comments
I think there is some content missing from your issue. From what I can join the dots, I think you're saying that if you don't specify columns via columnDefs, then the grid automatically creates columns based on the data. This is expected behaviour, and is a feature and not a bug. The columns should be able to be changed via gridOptions.columnDefs if you wanted to do so. A plunkr would help to explain what your concern is. |
Hi, playing around with it and I found that the problem was corrected in the latest version of the unstable release (I was using a copy which was 30 hours old!). What I am trying to do is replace the existing data with new data which has different column layout. However it tends to leave columns in which should have been removed. |
That is interesting. If you add 500, then 100, it has spare columns. But if you keep clicking on the 100 then the spare ones eventually go away. The code relies on there always being a name, even though that's not documented. I meant to do something about that - in buildColumns we have this code: // Synchronize self.columns with self.options.columnDefs so that columns can also be removed.
self.columns.forEach(function (column, index) {
if (!self.getColDef(column.name)) {
self.columns.splice(index, 1);
}
}); It looks up the columnDefs by column.name, and I think there's a couple of other places that assume there's a name. In 2.x you could just use field, but no more unfortunately. More importantly, I think the problem may be that code is using splice inside a forEach. I have a niggling feeling that that is a bad idea, as it breaks the loop construct (the array is getting shorter as we're trying to iterate over it). I need to check. I have some changes outstanding on this area of code anyway (#1685) which tidies up a few other things. It still needs one patch once I work out how to do it, and I could fix this at the same time. |
Thanks Paul - it is nice to have something which is "interesting" rather than it being caused by my lack of knowledge. |
In my application I do an insert, but I do it from outside the grid. I have a new button, and that pushes a new row to the end of the data. Then rowEdit calls the saveRow callback on it same as normal once the user is finished editing. In my callback I check whether it has an id so as to decide whether it's a save or update (using ngResource). I'm not sure that putting something extra into rowEdit would help - there's very little code in it. (And there's nowhere good to put a "new" button - it's better below the grid anyway). Delete is perhaps more interesting, in my grid I just put a delete button on each row, and again handle from outside the grid. But it would perhaps benefit from staying in the grid until physically deleted from the database. I'll think on that. |
Tidies up much of the column behaviour. Removed col.index everywhere it appears, except for in the cell content templates. For the cell content, replace with col.uid, which is now uniquely generated when the column is created, and never changed again. Should also fix angular-ui#1694, but need to push to be sure.
OK, it's updated to the ui-grid.info site, and rechecking the plunkr it looks fixed. |
Thanks Paul it works great! |
If I include ui-grid-row-edit, i.e. as follows:
the grid columns names are created automatically without setting grid columns in code and cannot be changed i.e. added or removed.
The text was updated successfully, but these errors were encountered: