Skip to content

Commit

Permalink
Call getColumnFromField from the apiRef
Browse files Browse the repository at this point in the history
  • Loading branch information
m4theushw committed Mar 29, 2021
1 parent b5e7f0e commit 5da9029
Showing 1 changed file with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import * as React from 'react';
import {
GRID_COLUMNS_UPDATED,
GRID_COLUMN_ORDER_CHANGE,
} from '../../../constants/eventsConstants';
import { GRID_COLUMNS_UPDATED, GRID_COLUMN_ORDER_CHANGE } from '../../../constants/eventsConstants';
import { GridApiRef } from '../../../models/api/gridApiRef';
import { GridColumnApi } from '../../../models/api/gridColumnApi';
import { gridCheckboxSelectionColDef } from '../../../models/colDef/gridCheckboxSelection';
Expand Down Expand Up @@ -174,13 +171,13 @@ export function useGridColumns(columns: GridColumns, apiRef: GridApiRef): void {
if (oldIndexPosition === targetIndexPosition) {
return;
}

logger.debug(`Moving column ${field} to index ${targetIndexPosition}`);

apiRef.current.publishEvent(GRID_COLUMN_ORDER_CHANGE, {
field,
element: apiRef.current.getColumnHeaderElement(field),
colDef: getColumnFromField(field),
colDef: apiRef.current.getColumnFromField(field),
targetIndex: targetIndexPosition,
oldIndex: oldIndexPosition,
api: apiRef.current,
Expand All @@ -190,7 +187,7 @@ export function useGridColumns(columns: GridColumns, apiRef: GridApiRef): void {
updatedColumns.splice(targetIndexPosition, 0, updatedColumns.splice(oldIndexPosition, 1)[0]);
updateState({ ...gridState.columns, all: updatedColumns });
},
[apiRef, getColumnFromField, gridState.columns, logger, updateState],
[apiRef, gridState.columns, logger, updateState],
);

const colApi: GridColumnApi = {
Expand Down

0 comments on commit 5da9029

Please sign in to comment.