quantopian / qgrid

An interactive grid for sorting, filtering, and editing DataFrames in Jupyter notebooks
Apache License 2.0
3.05k stars 421 forks source link

Set Formatter for Column Definitions #369

Open hshiravi opened 3 years ago

hshiravi commented 3 years ago

Trying to set a custom formatter when defining a column as specified here throws an error:

def customFormatter(row, cell, value, columnDef, dataContext):
  return value

col_def = {
    'A':{  'width': 50, 'formatter': customFormatter
    }
}

df = pd.DataFrame(np.random.random([5, 4]), columns =["A", "B", "C", "D"]) 
qgrid_widget = qgrid.show_grid(df, column_definitions=col_def)

This throws the following error: ValueError: Can't clean for JSON: <function customFormatter at 0x7f2cd4b5ec10>

How is one expected to set a custom formatter for a column?