| 130 | * @returns api to be used to interact with the grid. |
| 131 | */ |
| 132 | export function createGrid<TData>( |
| 133 | eGridDiv: HTMLElement, |
| 134 | gridOptions: GridOptions<TData>, |
| 135 | params?: Params |
| 136 | ): GridApi<TData> { |
| 137 | if (!gridOptions) { |
| 138 | _errorOnce('No gridOptions provided to createGrid'); |
| 139 | return {} as GridApi; |
| 140 | } |
| 141 | const api = new GridCoreCreator().create( |
| 142 | eGridDiv, |
| 143 | gridOptions, |
| 144 | (context) => { |
| 145 | const gridComp = new GridComp(eGridDiv); |
| 146 | context.createBean(gridComp); |
| 147 | }, |
| 148 | undefined, |
| 149 | params |
| 150 | ); |
| 151 | |
| 152 | // @deprecated v31 api no longer mutated onto the provided gridOptions |
| 153 | // Instead we place a getter that will log an error when accessed and direct users to the docs |
| 154 | // Only apply for direct usages of createGrid, not for frameworks |
| 155 | if (!Object.isFrozen(gridOptions) && !(params as GridParams)?.frameworkOverrides) { |
| 156 | const apiUrl = 'https://ag-grid.com/javascript-data-grid/grid-interface/#grid-api'; |
| 157 | Object.defineProperty(gridOptions, 'api', { |
| 158 | get: () => { |
| 159 | _errorOnce(`gridOptions.api is no longer supported. See ${apiUrl}.`); |
| 160 | return undefined; |
| 161 | }, |
| 162 | configurable: true, |
| 163 | }); |
| 164 | } |
| 165 | |
| 166 | return api; |
| 167 | } |
| 168 | /** |
| 169 | * @deprecated v31 use createGrid() instead |
| 170 | */ |