mercurymedia/elm-ag-grid/29.0.1

NOTE: the latest version is 34.0.1

AgGrid

AgGrid integration for elm.

Data Types

= AvgAggregation
| CountAggregation
| CustomAggregation String
| FirstAggregation
| LastAggregation
| MaxAggregation
| MinAggregation
| NoAggregation
| SumAggregation

Variants to aggregate values for a grouped column.

= AppEditor
{ componentName : String
, componentParams : Maybe Value
}
| LargeTextEditor
{ maxLength : Int
, rows : Int
, cols : Int
}
| SelectionEditor { values : List String }
| PredefinedEditor String
| DefaultEditor

CellEditor

  • DefaultEditor will set an editor derived from the renderer
  • LargeTextEditor will use the agLargeTextCellEditor
  • SelectionEditor will use the agRichSelectCellEditor
  • PredefinedEditor allows to use an existing ag-grid editor
  • AppEditor allows to use an Elm app as custom editor
type Column dataType
= Column (ColumnDef dataType)
| ColumnGroup (ColumnGroupDef dataType)

Column dataType

Represents a column in Aggird, this could be a normal or a group of columns

type alias ColumnSettings =
{ aggFunc : Aggregation
, allowedAggFuncs : Maybe (List Aggregation)
, autoHeight : Bool
, defaultAggFunc : Aggregation
, autoHeaderHeight : Bool
, cellClassRules : List ClassRule
, checkboxSelection : Bool
, customCellEditor : CellEditor
, editable : Eval Bool
, enablePivot : Bool
, enableRowGroup : Bool
, enableValue : Bool
, filter : FilterType
, filterParams :
{ buttons : List FilterButtonType
, closeOnApply : Bool
}
, filterValueGetter : Maybe String
, flex : Maybe Int
, floatingFilter : Bool
, headerCheckboxSelection : Bool
, hide : Bool
, lockPosition : LockPosition
, minWidth : Maybe Int
, pinned : PinningType
, lockPinned : Bool
, pivot : Bool
, pivotIndex : Maybe Int
, resizable : Bool
, rowGroup : Bool
, rowGroupIndex : Maybe Int
, showDisabledCheckboxes : Bool
, sortable : Bool
, sort : Sorting
, sortIndex : Maybe Int
, suppressColumnsToolPanel : Bool
, suppressFiltersToolPanel : Bool
, suppressMenu : Bool
, suppressSizeToFit : Bool
, valueFormatter : Maybe String
, valueGetter : Maybe String
, valueParser : Maybe String
, valueSetter : Maybe String
, width : Maybe Float
, wrapHeaderText : Bool
, wrapText : Bool
}

Column configuration settings.

= ColumnMoved
| ColumnResized
| ColumnVisible
| FilterChanged
| GridColumnsChanged
| SortChanged
| ColumnPinned
| ColumnRowGroupChanged
| ColumnValueChanged
| ResetColumns

Possible variants of callbacks that can lead to a certain change.

= DefaultFilter
| DateFilter
| NumberFilter
| StringFilter
| SetFilter
| NoFilter

Possible filter options for columns.

= LockToLeft
| LockToRight
| NoPositionLock

Lock a column to position to left or right to always have this column displayed in that position.

Or can be configured to not lock in one position and move the column freely.

= PinnedToLeft
| PinnedToRight
| Unpinned

Possible options to pin a column.

type Renderer dataType
= AppRenderer
{ componentName : String
, componentParams : Maybe Value
}
(dataType -> String)
| BoolRenderer (dataType -> Bool)
| CurrencyRenderer
{ countryCode : String
, currency : String
}
(dataType -> Maybe String)
| DecimalRenderer
{ countryCode : String
, decimalPlaces : Int
}
(dataType -> Maybe String)
| FloatRenderer (dataType -> Float)
| GroupRenderer (dataType -> String)
| IntRenderer (dataType -> Int)
| MaybeFloatRenderer (dataType -> Maybe Float)
| MaybeIntRenderer (dataType -> Maybe Int)
| MaybeStringRenderer (dataType -> Maybe String)
| DateRenderer (dataType -> String)
| NoRenderer
| PercentRenderer
{ countryCode : String
, decimalPlaces : Int
}
(dataType -> Maybe String)
| SelectionRenderer (dataType -> String) (List String)
| StringRenderer (dataType -> String)

The Renderer expresses how the data is retrieved from the list of data and rendered to the view.

The editor and renderer views in the table depend on the type. For example, a BoolRenderer is displayed and can be edited with a checkbox in the table.

The Renderer may need a function to read the value for the cell from the records.

Example

If the data is list of Product, the Renderer to display the column for the title might be defined as:

type alias Product =
    { title : String }


-- Column definitions:
[{ renderer = StringRenderer .title, ... }]
= AlwaysVisible
| NeverVisible
| OnlyWhenGroupingVisible

Row Group Panel allows the users to control which columns the rows are grouped by.

= MultipleRowSelection
| NoRowSelection
| SingleRowSelection

Type of row selection, set to either SingleRowSelection or MultipleRowSelection to enable selection.

  • SingleRowSelection will use single row selection, such that when you select a row, any previously selected row gets unselected.
  • MultipleRowSelection allows multiple rows to be selected.
  • NoRowSelection will not perform a row selection, only selecting the cell.
type Sorting
= SortAscending
| SortDescending
| NoSorting

Possible pre-configured column sorting.

type alias StateChange type_ =
{ event : { type_ : EventType }
, states : type_
}

Change event data for a table state changes.

type alias CsvExportParams =
{ fileName : String
, columnKeys : List String
}

Possible configuration for the CSV export.

type alias ExcelExportParams =
{ fileName : String
, columnKeys : List String
}

Possible configuration for the Excel export.

Grid

type alias GridConfig dataType =
{ autoGroupColumnDef :
{ cellRendererParams :
{ suppressCount : Bool
, checkbox : Bool
}
, headerName : Maybe String
, minWidth : Maybe Int
, resizable : Bool
, pinned : PinningType
}
, autoSizeColumns : Bool
, cacheQuickFilter : Bool
, columnStates : List ColumnState
, columnHoverHighlight : Bool
, contextMenu : Maybe ContextMenu
, csvExport : Maybe CsvExportParams
, detailRenderer :
Maybe
{ componentName : String
, componentParams : Maybe Value
, rowHeight : Maybe Int
}
, disableResizeOnScroll : Bool
, excelExport : Maybe ExcelExportParams
, filterStates : Dict String FilterState
, groupDefaultExpanded : Int
, groupIncludeFooter : Bool
, groupIncludeTotalFooter : Bool
, groupSelectsChildren : Bool
, isRowSelectable : dataType -> Bool
, maintainColumnOrder : Bool
, pagination : Bool
, quickFilterText : String
, rowGroupPanelShow : RowGroupPanelVisibility
, rowHeight : Maybe Int
, rowId : Maybe (dataType -> String)
, rowMultiSelectWithClick : Bool
, rowSelection : RowSelection
, rowClassRules : List ClassRule
, rowHoverHighlight : Bool
, selectedIds : List String
, sideBar : Sidebar
, size : String
, sizeToFitAfterFirstDataRendered : Bool
, stopEditingWhenCellsLoseFocus : Bool
, suppressAggFuncInHeader : Bool
, suppressMenuHide : Bool
, suppressRowClickSelection : Bool
, suppressRowDeselection : Bool
, themeClasses : Maybe String
}

Grid configurations.

GridConfig dataType
-> List (Attribute msg)
-> List (Column dataType)
-> List dataType
-> Html msg

Defines the data grid.

Example

let
    gridConfig =
        AgGrid.defaultGridConfig
            |> (\config -> { config | themeClasses = Just "ag-theme-balham ag-basic" })


    events =
        [ onCellChanged rowDecoder UpdateProduct ]


    defaultSettings =
        AgGrid.defaultSettings
            |> (\settings -> { settings | editable = True })


    columns =
        [ { field = "id"
          , renderer = IntRenderer .id
          , headerName = "Id"
          , settings = { defaultSettings | enablePivot = False }
          }
        , { field = "title"
          , renderer = StringRenderer .title
          , headerName = "Product"
          , settings = { defaultSettings | filter = StringFilter }
          }
        ]


    data =
        model.products
in
grid gridConfig events columns data

Defaults

defaultGridConfig : GridConfig dataType

Retrieve a GridConfig record with default configuration.

Can be used when implementing the grid.

    { autoGroupColumnDef =
        { cellRendererParams =
            { suppressCount = False
            , checkbox = False
            }
        , headerName = Nothing
        , minWidth = Nothing
        , resizable = True
        }
    , autoSizeColumns = False
    , cacheQuickFilter = False
    , columnStates = []
    , columnHoverHighlight = False
    , detailRenderer = Nothing
    , disableResizeOnScroll = False
    , filterStates = Dict.empty
    , groupDefaultExpanded = 0
    , groupIncludeFooter = False
    , groupIncludeTotalFooter = False
    , groupSelectsChildren = False
    , isRowSelectable = always True
    , pagination = False
    , quickFilterText = ""
    , rowGroupPanelShow = NeverVisible
    , rowHeight = Nothing
    , rowHoverHighlight = True
    , rowMultiSelectWithClick = False
    , rowSelection = MultipleRowSelection
    , selectedIds = []
    , sideBar = defaultSidebar
    , size = "65vh"
    , sizeToFitAfterFirstDataRendered = True
    , stopEditingWhenCellsLoseFocus = True
    , suppressAggFuncInHeader = False
    , suppressMenuHide = False
    , suppressRowClickSelection = False
    , suppressRowDeselection = False
    , themeClasses = Nothing
    }
defaultSettings : ColumnSettings

Retrieve a ColumnSettings record with default configuration.

Can be used when implementing column configurations for the table.

Default column settings:

{ aggFunc = NoAggregation
, allowedAggFuncs = Nothing
, autoHeight = False
, defaultAggFunc = SumAggregation
, autoHeaderHeight = False
, cellClassRules = []
, checkboxSelection = False
, customCellEditor = DefaultEditor
, editable = Const False
, enablePivot = True
, enableRowGroup = True
, enableValue = True
, filter = DefaultFilter
, filterParams =
    { buttons = [ ClearButton ]
    , closeOnApply = False
    }
, filterValueGetter = Nothing
, flex = Nothing
, floatingFilter = False
, headerCheckboxSelection = False
, hide = False
, lockPinned = False
, lockPosition = NoPositionLock
, minWidth = Nothing
, pinned = Unpinned
, pivot = False
, pivotIndex = Nothing
, resizable = True
, rowGroup = False
, rowGroupIndex = Nothing
, showDisabledCheckboxes = False
, sortable = True
, sort = NoSorting
, sortIndex = Nothing
, suppressColumnsToolPanel = False
, suppressFiltersToolPanel = False
, suppressMenu = False
, suppressSizeToFit = True
, valueFormatter = Nothing
, valueGetter = Nothing
, valueParser = Nothing
, valueSetter = Nothing
, width = Nothing
, wrapHeaderText = False
, wrapText = False
}

Events

onCellChanged : Decoder dataType -> (Result Error dataType -> msg) -> Attribute msg

Detect change events on cells.

Decodes the changed row according to the provided dataDecoder and passes the result to the message toMsg.

Handles the cellValueChanged event from Ag Grid.

Decoder dataType
-> (( Result Error dataType, String ) -> msg)
-> Attribute msg

Detect doubleclick events on cells.

Decodes the row of the clicked cell according to the provided dataDecoder and the field name of the clicked cells as tuple and passes the result to the message toMsg.

Handles the cellDoubleClicked event from Ag Grid.

Decoder dataType
-> (( Result Error dataType, String ) -> msg)
-> Attribute msg

Detect click events on cells.

Decodes the row of the clicked cell according to the provided dataDecoder and the field name of the clicked cells as tuple and passes the result to the message toMsg.

Handles the cellClicked event from Ag Grid.

onSelectionChange : Decoder node -> (Result Error (List node) -> msg) -> Attribute msg

Detect selection change events.

Sends the current selection of nodes to the toMsg.

Decoder dataType
-> (( Result Error dataType, String ) -> msg)
-> Attribute msg

Detect click on custom context menu actions

ColumnState

type alias ColumnState =
{ aggFunc : Maybe String
, colId : String
, flex : Maybe Int
, hide : Maybe Bool
, pinned : Maybe String
, pivot : Maybe Bool
, pivotIndex : Maybe Int
, rowGroup : Maybe Bool
, rowGroupIndex : Maybe Int
, sort : Maybe String
, sortIndex : Maybe Int
, width : Float
}

Column state.

Can be used to evaluate the current table state whenever a change to the structure of the table happens (e.g. sorting, order, sizing, or visiblity of columns changed).

Might be used to persist the table state of the user to the localstorage or some other external storage. Column states can be restored through the columnState on the GridConfig.

onColumnStateChanged : (StateChange (List ColumnState) -> msg) -> Attribute msg

Detect change events to the table structure (e.g. sorting or moved columns).

Decodes the EventType of the change and the current states of the grid columns and passes the result to the toMsg.

columnStatesDecoder : Decoder (List ColumnState)

Decoder for the current column states.

Can be used to retrieve and decode the column states from an external storage.

columnStatesEncoder : List ColumnState -> Value

Encode a collection of ColumnState.

Can be used to persist the current list of ColumnState for the grid to an external storage.

GridConfig dataType
-> List (Column dataType)
-> List (Column dataType)

Apply the column state from the GridConfig to the given ColumnDefs.

The values from the cache overwrite the values on the ColumnDef. The order is also according to the order in the column state. New columns, that don't exist in the column state, are appended to the end.

This function is mainly exposed to allow unit-testing, as this is automatically applied to ColumnDefs passed to the grid.

FilterState

= TextFilterState TextFilterAttrs
| NumberFilterState NumberFilterAttrs
| DateFilterState DateFilterAttrs
| SetFilterState SetFilterAttrs

Filter state.

Can be used to evaluate the current filter configuration whenever a filter on a column gets changed.

Might be used to persist the filters applied to the table for the users to the localstorage or some other external storage. Filter states can be restored through the filterState on the GridConfig.

AG Grid reference: https://www.ag-grid.com/javascript-data-grid/filtering/#column-filter-types

onFilterStateChanged : (StateChange (Dict String FilterState) -> msg) -> Attribute msg

Detect change events to the table filters.

Decodes the EventType of the change and the filter configuration of the grid columns and passes the result to the toMsg.

filterStatesEncoder : Dict String FilterState -> Value

Encode a collection of FilterState.

Can be used to persist the current collection of FilterState for the grid to an external storage.

filterStatesDecoder : Decoder (Dict String FilterState)

Decoder for the filter states.

Can be used to retrieve and decode the filter states from an external storage.

Sidebar

= ColumnSidebar
| FilterSidebar

Possible options for displayed sidebars.

= SidebarLeft
| SidebarRight

Position for the sidebar.

defaultSidebar : Sidebar

Retrieve a Sidebar with default configuration.

Can be used to ease the sidebar configuration.

    { panels = []
    , defaultToolPanel = Nothing
    , position = SidebarRight
    }

Type parser

Stringify an Aggregation.

This matches the configuration for AgGrid and equals the value retrieved from the ColumnState. Further, it can be used for external communication if necessary.

Stringify a PinningType.

This matches the configuration for AgGrid and equals the value retrieved from the ColumnState. Further, it can be used for external communication if necessary.

sortingToString : Sorting -> Maybe String

Stringify the Sorting.

This matches the configuration for AgGrid and equals the value retrieved from the ColumnState. Further, it can be used for external communication if necessary.

toAggregation : Maybe String -> Aggregation

Parse a string to an Aggregation.

This can be used in combination with the value on the ColumnState. Further, it can be used for external communication if necessary.

toPinningType : Maybe String -> PinningType

Parse a string to a PinningType.

This can be used in combination with the value on the ColumnState. Further, it can be used for external communication if necessary.

toSorting : Maybe String -> Sorting

Parse a string to the Sorting type.

This can be used in combination with the value on the ColumnState. Further, it can be used for external communication if necessary.