Comments (6)
How about changing the column header directly in SlickGrid? See this SO question. To have access to the grid object, see more info in the Wiki - OnEvent, use the Event Emitter (onGridCreated)="gridReady($event)"
Also I don't think that using the ngOnChanges
will be good, I already have a getter/setter on the dataset
object because it could change at any moment. The dataset
setter could be in conflict with the
ngOnChanges
. However, moving the code from ngAfterViewInit
into an initialize
function that can be called by the ngAfterViewInit
and a new setter on the columnDefinitions
is a possibility. I wouldn't do it on all properties though, especially not the gridOptions
since some of it's properties can be changed on the fly and we shouldn't have to re-create the grid every time for that.
from angular-slickgrid.
I have to do some quick fixes in the lib and gave a quick try to do what I wrote in previous comment, but it doesn't work so good. I get a few different kind of errors with the services.
I think the best option is to have a service that supports adding or modifying the SlickGrid column definition dynamically. This SO question is probably the best way to do it.
I have undone all the changes since it brought more problems.
For reference, this is what I tried.
- Move the grid creation into a
gridInitialization
function - Make the
columnDefinitions
a getter/setter - On any subsequent
columnDefinitions
changes, call thegridInitialization
function
Here's the code
didAfterViewInitRan = false;
@Input()
set columnDefinitions(columnDefinitions: Column[]) {
this._columnDefinitions = columnDefinitions;
if (this.didAfterViewInitRan) {
this.initialization();
}
}
get columnDefinitions(): Column[] {
return this._columnDefinitions;
}
ngAfterViewInit() {
this.initialization();
this.didAfterViewInitRan = true;
}
initialization() {
// create the grid in here
}
from angular-slickgrid.
I am doubtful that this would work for a few reasons,
- This will still only call the initialization only once. If the first time it is called with this._columnDefinitions as undefined (this is what happened to me) then the second time when actual data is set will still be of no use since you are setting a flag.
- You can remove the setters and getters and handle those in the ngOnChanges as I feel they are more logically places to update the component when the data changes.
- ngOnChanges can be implemented so that internal changes are only made for certain actions like data or header changes and both can trigger different set of update actions within the component.
from angular-slickgrid.
The commit that I made made this partially working, it does add the column to the definition list and we do see it in the grid. However, most of the services in Angular-Slickgrid are initialized through init(this.grid, this.gridOptions, this.columnDefinitions)
and because of that last part, then not all services have the updated column definitions. The first misbehavior that I saw was that I use headerKey
for i18n translation and adding a new column header worked but it wasn't translated because the service that translate them didn't get latest column definitions.
To fix the service not having all column definitions and grid options, there 2 ways to deal with that
- Use a shared Service to pass shared variable, like
this.grid
,this.gridOptions
, etc... - Still use
init()
for all Services but only passthis.grid
to them, since we can get the gridOptions and columnDefinitions directly from the grid object.
I would opt for option 2, but that will take some time and that would fix the misbehavior I describe on top. Will that fix all problems? I don't know but that would be a good start.
Or if you think your approach is still the best, then I certainly welcome PR if you can make it work and all examples still works.
from angular-slickgrid.
I have pushed a new version 0.13.4
to NPM which has the commit made yesterday. It doesn't fix everything, but it's a start. The change does bring a setter to the columnDefinitions
and it adds a column header dynamically.
from angular-slickgrid.
With the latest PR #28 and extra commit it is now possible to change dynamically, at any point in time, Grid Options and Column Definitions. The Services, will always use the latest properties from the Grid object. This officially bring support to dynamic Grid Options and Column Definitions.
Changing a Grid Options is instant and does not need a Setter internally, however changing the Column Definitions will trigger a change with a Setter on the columnDefinitions
object to make sure that it also re-translate header if it needs to.
Test Code
dynamicallyAddHeader() {
this.columnDefinitions.push({ id: 'title2', field: 'id', headerKey: 'TITLE', formatter: this.taskTranslateFormatter, sortable: true, minWidth: 100, filterable: true, params: { useFormatterOuputToFilter: true } });
this.columnDefinitions = this.columnDefinitions.slice();
}
With the new version, we can add a new Column and change Grid Options dynamically and all Services are working as expected since they will get the properties at when it reaches the Service through the Grid object, all Services are basically doing something like this:
const gridOptions = this._grid.getOptions();
const columnDefinitions = this._grid.getColumns();
which fixes the original issue reported.
This is now available in version 0.17.0
from angular-slickgrid.
Related Issues (20)
- Frozen columns do not fit in viewport HOT 3
- The Multi-column tri-state sorting option doesn't work HOT 2
- Boolean column with filter collection and render html not working, displays true/false HOT 7
- Update Step By Step Install Wiki page HOT 10
- Example 22 keeps formatter components alive outside of grid HOT 20
- Example 22 shows temp ng-template being rendered for a short period
- cell highlighted stays on the same position even when filtered HOT 1
- Attach Angular Component in AsyncPostRender and keep it running HOT 2
- I have issues with Editor text box. HOT 6
- I am getting error when I use multipleSelect . "Cannot find type definition file for 'trusted-types'. " HOT 9
- Shared module gridOptions seetings not preserve in page module HOT 15
- All items in grid appear highlighted after adding an item to the grid HOT 9
- Incorrect dataContext is passed in `onSave` callback using composite editor HOT 6
- Polyfills ERROR TypeError: Function.prototype.toString requires that 'this' be a Function at Boolean.toString (<anonymous>) HOT 25
- Custom header and footer templates, like for Aurelia
- No data warning stays if data lazy loaded and gridOptions changed HOT 12
- Angular slickgrid upgrade does not working HOT 3
- between Operator HOT 1
- Angular esbuild error on DomPurify with rowDetailView and no pre/post template HOT 5
- CSP compliance HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular-slickgrid.