'get notified when igx-grid has done loading
I am trying to move a dynamic column to different position using Infragistics Angular grid, igx-grid. I tried with
const newCol = this.grid.getColumnByName(node);
newCol?.move(j);
but newCol is null since grid has not finished loading and new dynamic column has not been applied. So I need to do this after grid is done loading. What event can I subscribe to get this done? Thanks
Solution 1:[1]
You can use rendered event emitter which is emitted after the ngAfterViewInit hook. At this point, the grid exists in the DOM. StackBlitz sample and official igxGrid topic.
<igx-grid #grid1 [data]="data" [paging]="true" [primaryKey]="'ProductID'"
(rendered)="rendered()">
Solution 2:[2]
It looks that by the time being, the only way is actually keeping a reference manually.
Maybe a decorator is something more convenient than having to manually add the code in each async function. I opted for the class design, so that a class attribute can hold the hard-references while the tasks run. (A local variable in the wrapper function would be part of the task-reference cycle, and the garbage collection would trigger all the same):
# run and visit http://localhost:8080/ in your browser
import asyncio
import gc
from functools import wraps
import weakref
class Shielded:
registry = set()
def __init__(self, func):
self.func = func
async def __call__(self, *args, **kw):
self.registry.add(task:=asyncio.current_task())
try:
result = await self.func(*args, **kw)
finally:
self.registry.remove(task)
return result
def _Shielded(func):
# Used along with the print sequence to assert the task was actually destroyed without commenting
async def wrapper(*args, **kwargs):
ref = weakref.finalize(asyncio.current_task(), lambda: print("task destroyed"))
return await func(*args, **kwargs)
return wrapper
@Shielded
async def client_connected_cb(reader, writer):
print("at task start")
#registry.append(asyncio.current_task())
# I've connected this to a socket in an interactive session, I'd explictly .close() for debugging:
remote_read, remote_write = await asyncio.open_connection("localhost", 8060, ssl=False)
print("comensing remote read")
await remote_read.read()
print("task complete")
async def cleanup():
while True:
gc.collect()
await asyncio.sleep(1)
async def main():
server = await asyncio.start_server(client_connected_cb, "localhost", 8080)
await asyncio.gather(server.serve_forever(), cleanup())
asyncio.run(main())
Moreover, I wanted to "really see it", so I created a "fake" _Shielded
decorator that would just log something when the underlying task
got deleted: "task complete" is never printed with it, indeed.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Konstantin Dinev |
| Solution 2 | jsbueno |
