Skip to content

Expose raw events for OnColumnGroupOpened and OnGridReady #52

Open
@Larocceau

Description

@Larocceau

For the OnGridReady and OnColumnGroupOpened, instead of mapping the AgGrid API directly, we expose a limited set of utility functions:

static member onColumnGroupOpened(callback: _ -> unit) = // This can't be inline otherwise Fable produces invalid JS
    let onColumnGroupOpened =
        fun ev ->
            {|
                AutoSizeGroupColumns =
                    fun () ->
                        // Runs the column autoSize in a 0ms timeout so that the cellRenderer cells render before
                        // the grid calculates how large each cell is
                        JS.setTimeout
                            (fun () ->
                                let colIds =
                                    ev?columnGroups
                                    |> Seq.head
                                    |> fun cg -> cg?children
                                    |> Array.map (fun x -> x?colId)

                                ev?api?autoSizeColumns colIds)
                            0
                        |> ignore
            |}
            |> callback
static member onGridReady(callback: _ -> unit) = // This can't be inline otherwise Fable produces invalid JS
    let onGridReady =
        fun ev ->
            {|
                AutoSizeAllColumns =
                    fun () ->
                        // Runs the column autoSize in a 0ms timeout so that the cellRendererFramework cells render
                        // before the grid calculates how large each cell is
                        JS.setTimeout
                            (fun () ->
                                let colIds = ev?api?getColumns () |> Array.map (fun x -> x?colId)
                                ev?api?autoSizeColumns colIds)
                            0
                        |> ignore
                Export = fun () -> ev?api?exportDataAsCsv (obj ())
            |}
            |> callback

This severely restricts the flexibility the user has in handling this event; there should be an overload for these that just exposes the event:

type AgGrid<'row> =
   ....
   static member onGridReady(OnGridReadyEvent -> unit)
   static member onColumnGroupOpened (OnColumnGroupOpenedEvent -> unit)

The utility functions can be implemented using type extensions on the event (or most cases even the grid API), located in a separate module to make it clear that these are not native AGGrid features

I suggest deprecating the current event handlers, as the behaviour of having multiple of these events is undefined

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions