Budibase / svelte-ag-grid

A svelte wrapper component around ag-grid
MIT License
24 stars 14 forks source link

Do not override user defined event functions #9

Open roydukkey opened 3 years ago

roydukkey commented 3 years ago

It is not currently possible for the consumer to define their own onGridReady, onCellValueChanged, onSelectionChanged since they are override by the onMount functionality.

https://github.com/Budibase/svelte-ag-grid/blob/9d19c4c991ed9034510cc3754a551029a8c3d691/src/Component.svelte#L49-L58

I think it would be find to assume that over event's should fire before any user defined events, so I would propose this solution, implement similarly for all three events.


let consumerOnGridReady;

const onGridReady = (params) => {
    api = grid.gridOptions.api;
    if (loading) api.showLoadingOverlay();
    if (consumerOnGridReady) consumerOnGridReady(params);
};

onMount(() => {
    if (options.onGridReady) {
        consumerOnGridReady = options.onGridReady;
    }

    grid = new Grid(ref, {
        ...options,
        columnDefs,
        rowData: data,
        onGridReady,
        onCellValueChanged,
        onSelectionChanged,
    });
});
roydukkey commented 3 years ago

Here's a working branch for this: https://github.com/Budibase/svelte-ag-grid/compare/master...roydukkey:issue/9.

I know this adds more complexity to the wrapper, which is intended to be lightweight, so if this is undesired, I'll keep this on my fork otherwise, I'll submit a PR.

Also, note that I have changed how the api field is recorded. Accessing the event rather than the grid's grid options should be slightly quicker.