2.1.2 • Published 2 years ago

espalier-js v2.1.2

Weekly downloads
6
License
MIT
Repository
-
Last release
2 years ago

EspalierJS

Espalier JS is an easy-to-use grid component for Aurelia.

How to install EspalierJS

EspalierJS is published as an NPM package, and can be added to Aurelia as a plugin. To get up and running using EspalierJS, first install it from NPM:

$ npm install espalier-js

If you're using the Aurelia CLI (and you should be!), add EspalierJS into your configuration. For the default RequireJS Aurelia CLI configuration, add the following to your dependencies:

{
  "name": "espalier-js",
  "path": "../node_modules/espalier-js/dist/amd",
  "main": "index",
  "resources": [
    "**/*.{css,html}"
  ]
}

If you are using the Webpack Aurelia CLI configuration, add espalier-js to the ModuleDependenciesPlugin in your webpack.config.js as such:

new ModuleDependenciesPlugin({
  'aurelia-testing': [ './compile-spy', './view-spy' ],
  'aurelia-fetch-client': [ './aurelia-fetch-client' ],
  'espalier-js': [ './index' ]
})

Once Espalier is set up in your dependencies, register it as an Aurelia plugin in your application's main:

aurelia.use
  .standardConfiguration()
  .feature("resources")
  .plugin("espalier-js");

The EspalierJS grid can now be used by adding an <espalier url="{api to use}" settings.bind="gridSettings"></espalier> element to a page.

How to set up a sweet pageable, sortable, filterable grid in Aurelia

For the most basic configuration for an Espalier grid, add an espalier element to your view, specify the API url it will fetch from, and bind it to a settings model in your view.

In your HTML:

<espalier url="/my-api-endpoint" settings.bind="gridSettings"></espalier>

In your view model:

import { IEspalierSettings } from "espalier-js";

export class ViewModel {
  public filter: LookupsFilter;
  public gridSettings: IEspalierSettings<TRow>;

  public attached() {
    this.gridSettings = {
      columns: [
        { propertyName: "Name" }
      ]
    };
  }
}

Configuring Espalier globally to know your API

Out of the box Espalier expects your API to accept the following parameters:

{api endpoint}?Page=1&PageSize=10&SortOn=Name&SortOrder=asc

The default sort order tokens are asc and desc. These expectations can all be globally configured. The easiest way to globally configure these values is to import EspalierConfig into your app class, and set the configuration to match your API. Because Aurelia dependency injection treats models such as these as a singleton, the values you set in the app class will persist throughout your application.

import { EspalierConfig } from "espalier-js";

@autoinject
export class App {
  constructor(espalierConfig: EspalierConfig) {
      espalierConfig.defaultPageSize = 20;
      espalierConfig.pageParameterName = "filter.page";
      espalierConfig.pageSizeParameterName = "filter.pageSize";
      espalierConfig.sortOnParameterName = "filter.sortOn";
      espalierConfig.sortOrderParameterName = "filter.sortOrder";
      espalierConfig.buttonColor = "rgb(11,66,104)";
  }
}

View the documentation for EspalierConfig to see all the available options.

Configuring an Espalier instance

Individual instances of Espalier can be configured both through binding on the element in HTML, and an instance of IEspalierSettings<TRow> interface. The options that can be bound in the HTML are:

page-size

A number representing the number of records to fetch per page. This defaults to the value set in the global configuration if none is specified. This value is not required.

default-filter

The default filter to append to the query string in addition to paging and sorting parameters. This value is only used if there is not an advanced filter in place. There is more on advanced filtering later in this document. This value is not required.

url

The URL Espalier will call (using the Aurelia Fetch Client) to retrieve records to display in the grid. If you have configured your fetch client with a base URL, this is a relative path to the API endpoint you wish to consume. This value is required.

The other instance-related options that can be configured using an IEspalierSettings<TRow>.

Filtering an Espalier grid

To filter an Espalier grid, create a control that implements EspalierFilter.

import { EspalierFilter } from "espalier-js";
import { MyFilterModel } from "./my-filter-model";
import { customElement } from "aurelia-framework";

@customElement("my-filter")
export class LookupsFilter extends EspalierFilter {
  public container: HTMLFormElement;
  protected model: MyFilterModel = new MyFilterModel();

  protected get appliedFilters(): IFilterToken[] {
    return this.model.getTokens();
  }

  protected get filterAsQueryString(): string {
    return this.model.buildFilter();
  }

  protected clearFilter(): Promise<void> {
    return new Promise<void>((resolve) => {
      this.resetModel();
      resolve();
    });
  }

  private resetModel() {
    this.model.reset();
  }
}

Then import the filter control into the page with the Espalier grid, and bind the filter to the grid settings:

<template>
  <require from="./my-filter"></require>
  <h2>Some Data</h2>
  <espalier url="/some-api" settings.bind="tableSettings"></espalier>
  <my-filter view-model.ref="filter"></my-filter>
</template>
import { IEspalierSettings } from "espalier-js";
import { IModel } from "./my-model";
import { MyFilter } from "./my-filter";

export class SomeData {
  public filter: MyFilter;
  public tableSettings: IEspalierSettings<IModel>;

  public attached() {
    this.tableSettings = {
      columns: [
        { propertyName: "Name" }
      ],
      filter: this.filter
    };
  }
}
2.1.2

2 years ago

2.1.1

2 years ago

2.1.0

2 years ago

1.0.0

2 years ago

2.0.15

5 years ago

2.0.14

6 years ago

2.0.13

6 years ago

2.0.12

6 years ago

2.0.11

6 years ago

2.0.10

6 years ago

2.0.9

6 years ago

2.0.8

6 years ago

2.0.7

6 years ago

2.0.6

6 years ago

2.0.5

6 years ago

2.0.4

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.2.1

6 years ago

1.1.38

6 years ago

1.1.37

7 years ago

1.1.36

7 years ago

1.1.35

7 years ago

1.1.34

7 years ago

1.1.33

7 years ago

1.1.32

7 years ago

1.1.31

7 years ago

1.1.30

7 years ago

1.1.29

7 years ago

1.1.28

7 years ago

1.1.27

7 years ago

1.1.26

7 years ago

1.1.25

7 years ago

1.1.24

7 years ago

1.1.23

7 years ago

1.1.22

7 years ago

1.1.21

7 years ago

1.1.20

7 years ago

1.1.19

7 years ago

1.1.18

7 years ago

1.1.17

7 years ago

1.1.16

7 years ago

1.1.15

7 years ago

1.1.14

7 years ago

1.1.13

7 years ago

1.1.12

7 years ago

1.1.11

7 years ago

1.1.10

7 years ago

1.1.9

7 years ago

1.1.8

7 years ago

1.1.7

7 years ago

1.1.6

7 years ago

1.1.5

7 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

0.4.14

8 years ago

0.4.13

8 years ago

0.4.12

8 years ago

0.4.11

8 years ago

0.4.10

8 years ago

0.4.9

8 years ago

0.4.8

8 years ago

0.4.7

8 years ago

0.4.6

8 years ago

0.4.5

8 years ago

0.4.4

8 years ago

0.4.3

8 years ago

0.4.2

8 years ago

0.4.1

8 years ago

0.3.147

8 years ago

0.3.146

9 years ago

0.3.145

9 years ago

0.3.144

9 years ago

0.3.143

9 years ago

0.3.142

9 years ago

0.3.141

9 years ago

0.3.140

9 years ago

0.3.139

9 years ago

0.3.137

9 years ago

0.3.136

9 years ago

0.3.135

9 years ago

0.3.134

9 years ago

0.3.133

9 years ago

0.3.132

9 years ago

0.3.131

9 years ago

0.3.130

9 years ago

0.3.129

9 years ago

0.3.128

9 years ago

0.3.127

9 years ago

0.3.126

9 years ago

0.3.125

9 years ago

0.3.124

9 years ago

0.3.123

9 years ago

0.3.122

9 years ago

0.3.121

9 years ago

0.3.120

9 years ago

0.3.119

9 years ago

0.3.118

9 years ago

0.3.117

9 years ago

0.3.116

9 years ago

0.3.115

9 years ago

0.3.114

9 years ago

0.3.113

9 years ago

0.3.112

9 years ago

0.3.111

9 years ago

0.3.110

9 years ago

0.3.109

9 years ago

0.3.108

9 years ago

0.3.107

9 years ago

0.3.106

9 years ago

0.3.105

9 years ago

0.3.104

9 years ago

0.3.103

9 years ago

0.3.102

9 years ago

0.3.101

9 years ago

0.3.100

9 years ago

0.3.99

9 years ago

0.3.98

9 years ago

0.3.97

9 years ago

0.3.96

9 years ago

0.3.95

9 years ago

0.3.94

9 years ago

0.3.93

9 years ago

0.3.92

9 years ago

0.3.91

9 years ago

0.3.90

9 years ago

0.3.89

9 years ago

0.3.88

9 years ago

0.3.87

9 years ago

0.3.86

9 years ago

0.3.85

9 years ago

0.3.84

9 years ago

0.3.83

9 years ago

0.3.82

9 years ago

0.3.81

9 years ago

0.3.80

9 years ago

0.3.79

9 years ago

0.3.78

9 years ago

0.3.77

9 years ago

0.3.76

9 years ago

0.3.75

9 years ago

0.3.74

9 years ago

0.3.73

9 years ago

0.3.72

9 years ago

0.3.71

9 years ago

0.3.70

9 years ago

0.3.69

9 years ago

0.3.68

9 years ago

0.3.67

9 years ago

0.3.66

9 years ago

0.3.65

9 years ago

0.3.64

9 years ago

0.3.63

9 years ago

0.3.62

9 years ago

0.3.61

9 years ago

0.3.60

9 years ago

0.3.59

9 years ago

0.3.58

9 years ago

0.3.57

9 years ago

0.3.56

9 years ago

0.3.55

9 years ago

0.3.54

9 years ago

0.3.53

9 years ago

0.3.52

9 years ago

0.3.51

9 years ago

0.3.50

9 years ago

0.3.49

9 years ago

0.3.48

9 years ago

0.3.47

9 years ago

0.3.46

9 years ago

0.3.45

9 years ago

0.3.44

9 years ago

0.3.43

9 years ago

0.3.42

9 years ago

0.3.41

9 years ago

0.3.40

9 years ago

0.3.39

9 years ago

0.3.38

9 years ago

0.3.37

9 years ago

0.3.36

9 years ago

0.3.35

9 years ago

0.3.34

9 years ago

0.3.33

9 years ago

0.3.32

9 years ago

0.3.31

9 years ago

0.3.30

9 years ago

0.3.29

9 years ago

0.3.28

9 years ago

0.3.27

9 years ago

0.3.26

9 years ago

0.3.25

9 years ago

0.3.24

9 years ago

0.3.23

9 years ago

0.3.22

9 years ago

0.3.21

9 years ago

0.3.20

9 years ago

0.3.19

9 years ago

0.3.18

9 years ago

0.3.17

9 years ago

0.3.16

9 years ago

0.3.15

9 years ago

0.3.14

9 years ago

0.3.13

9 years ago

0.3.12

9 years ago

0.3.11

9 years ago

0.3.10

9 years ago

0.3.9

9 years ago

0.3.8

9 years ago

0.3.7

9 years ago

0.3.6

9 years ago

0.3.5

9 years ago

0.3.4

9 years ago

0.3.3

9 years ago

0.3.2

9 years ago

0.3.1

9 years ago

0.2.22

9 years ago

0.2.21

9 years ago

0.2.20

9 years ago

0.2.19

9 years ago

0.2.18

9 years ago

0.2.17

9 years ago

0.2.16

9 years ago

0.2.15

9 years ago

0.2.14

9 years ago

0.2.13

9 years ago

0.2.12

9 years ago

0.2.11

9 years ago

0.2.10

9 years ago

0.2.9

9 years ago

0.2.8

9 years ago

0.2.7

9 years ago

0.2.6

9 years ago

0.2.5

9 years ago

0.2.4

9 years ago

0.2.3

9 years ago

0.2.2

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago