mercurymedia / elm-ag-grid / AgGrid.Expression

Integration of Expressions for AgGrid. A Expression will be encoded and evaluated in javascript.

For more information take a look at https://github.com/mercurymedia/elm-ag-grid/blob/10.0.0/ag-grid-webcomponent/expression.js.

Definition


type Eval a
    = Const a
    | Expr Expression

Eval a can be a Cosnt a or and Expr

A `Const a` will pass the value of the type `a` directly to the `AgGrid` attribute in javascript.
A `Expr` will frist evaluated in javascript and than passed to the `AgGrid` attribute.


type Expression

A Expression covers some basic operators to evaluate

At this moment this only covers very basic operations


type Literal

The Literal type represents literals for strings, ints and floats.


type Operator

A Operator take expression(s) and evaluate the result in javascript.

Operators

or : Expression -> Expression -> Expression

Represents the || operator

Expression.or (Expression.value "likesElm") (Expression.value "isProgrammer")

and : Expression -> Expression -> Expression

Represents the && operator

Expression.and (Expression.value "likesElm") (Expression.value "isProgrammer")

eq : Expression -> Expression -> Expression

Represents the == operator

Expression.eq (Expression.int 18) (Expression.value "age")

lte : Expression -> Expression -> Expression

Represents the <= operator

Expression.lte (Expression.int 18) (Expression.value "age")

gte : Expression -> Expression -> Expression

Represents the >= operator

Expression.gte (Expression.int 18) (Expression.value "age")

not : Expression -> Expression

Represents the ! operator

Expression.not (Expression.value "isActive")

includes : Expression -> Expression -> Expression

Performs the javascript Array.inclues function

Expression.includes (Expression.string "Tim") (Expression.value "names")
Where names is a list of Strings.

Literals

bool : Basics.Bool -> Expression

A bool literal

Expression.bool True

int : Basics.Int -> Expression

An int Literal

Expression.int 18

string : String -> Expression

A string Literal

Expression.string "Tim"

float : Basics.Float -> Expression

A float Literal

Expression.float 13.37

list : List String -> Expression

A string-list literal

Expression.list [ "a", "b" ]

Row values

value : String -> Expression

The value function can be used to get a value from the data object passed in from a callback of AgGrid.

For example when it comes to disable a contextMenu entry, you can get a value from the current clicked row.

type alias Row =
    { age : Int }

columnDefs =
    [ { field = "age"
      , renderer = IntRenderer .age
      , headerName = "Age"
      , settings = AgGrid.defaultSettings
      }
    ]

contextMenu =
    [ AgGridContextMenu.contextAction
        { defaultActionAttributes
            | name = "Full age action"
            , actionName = Just "fullAgeAction"
            , disabled = Expression.Expr (Expression.lte (Expression.value "age") (Expression.int 18))
        }
    ]

Encoding

encode : (a -> Json.Encode.Value) -> Eval a -> Json.Encode.Value

The encode encodes a evaluation.