GithubHelp home page GithubHelp logo

corneliutusnea / aurelia-grid Goto Github PK

View Code? Open in Web Editor NEW
15.0 4.0 19.0 115 KB

A fresh Aurelia Grid written in TypeScript based charlespockert's Aurelia BS Grid

JavaScript 59.93% CSS 5.33% HTML 8.54% TypeScript 26.21%

aurelia-grid's Introduction

aurelia-grid

A fresh Aurelia Grid written in TypeScript based charlespockert's Aurelia BS Grid.

Gitter

Intro

This is an early build of an Aurelia Grid based on an original implementation by charlespockert's Aurelia BS Grid.

Features:

  • Column Header Templates
  • Row Cell Templates
  • Pagination
  • Single column and Multi Column Sorting
  • Local Data Source and Delegated data source
  • Pager with custom Pager Templates

Upcoming Features:

  • Remote Data Source
  • Multi-Select
  • Column Filters

Documentation

Using the grid

  1. Install the plugin into your project using jspm
jspm install github:corneliutusnea/aurelia-grid

Note: I'm still missing the config for JSPM to install this package! Alternatively (if you are using webpack) you can install the package using npm

npm install aurelia-grid
  1. In order to import the plugin you need to be manually bootstrapping Aurelia.

Open your index.html or equivalent and find your aurelia-app attribute and change it to:

  <body aurelia-app="main">
  1. Create a main.js file in your src directory and import the plugin using the aurelia configuration object
export function configure(aurelia) {
  aurelia.use
    .standardConfiguration()
    .developmentLogging()
    // Install the plugin
    .plugin('corneliutusnea/aurelia-grid');
  aurelia.start().then(a => a.setRoot());
}
  1. Since the plugin is globalized, you can use it by placing a <grid> custom element in any of your views:
  <grid source-read.call="getSomeData($event)">
    <!-- Row template -->
    <grid-row>
      <!-- Column template(s) -->
      <grid-col heading="ID" field="id" class="col-md-6">${ $item.id }</grid-col>
      <grid-col heading="Name" field="name" class="col-md-6">${ $item.name }</grid-col>
    </grid-row>
  </grid>

You can specify the columns and their templates in-line in the markup. This gives you a view-friendly way of defining a data-grid so you can safely re-use your viewmodels.

The Template

<!-- Grid plugin element -->
<grid>
	<!-- Row template -->
	<grid-row>
		<!-- Columns -->
		<grid-col><!-- Column template --></grid-col>
		<grid-col><!-- Column template --></grid-col>
	</grid-row>
	<!-- Optional Grid Pager options -->
	<grid-pager>
	</grid-pager>
</grid>

You should provide a <grid-row> element and one or more child <grid-col> elements.

<grid-row>

This represents a row of bound data. Any attributes applied to this element will be forwarded to the rows generated in the grid, so you can style your rows by applying classes to this element:

<grid-row class="row-style" other-attribute="true">...

This will generate the following grid rows:

<tr class="my-custom-row au-target" other-attribute="true">...</tr>

(Few extra grid specific attributes will be added to the row.)

<grid-col>

This represents a column in your grid - the same rules apply to grid columns in that any attributes will be forwarded to each grid cell that's generated.

grid-col attributes

  • heading - Title of the column
  • field - Name of the field in the incoming item. Only required if the field supports sorting
  • class - CSS Class for the column when rendering the item
  • header-class - CSS class for the column header (the th)
  • can-sort="true|false" - switch to allow sorting on this column. (default is false).
  • canFilter="true|false" - switch to allow filtering on this column. (default is false)
  • sorting="asc|desc" - can't be set by default but can be used in the template

Grid Column - Row Templates

Anything between the column tags will be the column template. You can place any HTML markup in here and it will be picked up and compiled by Aurelia, so you can interpolate, attach event handlers, bind to expressions etc etc. You can reference the current data row in the template by using the special $item field Example

<grid-column heading="Customer Name" field="customerName" class="col-md-6 col-customer-name" header-class="col-md-6" can-sort="true" can-filter="true">${item.customerName}</grid-column>

Grid Column - Header Templates

You can also create custom templates for both header and row cell by adding two elements into the grid column <heading> and <template>:

<grid-col can-sort="true" field="id" class="col-xs-1">
	<heading><strong>${$column.heading} - ${$column.sorting}</strong></heading>
	<template>${$item.id}</template>
</grid-col>

Note: If no <template> is found the grid will assume all your content is the row cell template. The heading="name" attribute is ignored if a <heading> element is found inside the <grid-col> but it's filled in from the attributes list so you can still use it in your heading template.

Inside the Grid Heading Template you have access to the following properties

  • $column - the current column with all its properties as defined above in grid-col
  • $grid - direct reference to the grid. Best if you don't use this directly as the implementation can change.

Default Grid Column Heading template is:

<span class="grid-column-heading">${$column.heading}</span>
<span if.bind="$column.sorting === \'desc\'" class="glyphicon glyphicon-triangle-top text-primary"></span>
<span if.bind="$column.sorting === \'asc\'" class="glyphicon glyphicon-triangle-bottom text-primary"></span>

Note: Each row will be in the scope of the repeat element, so in order to get back to your consuming viewmodel you need to jump up two levels (up to the grid scope then up to your viewmodel scope) You can use $grid to reference the grid scope and $p to get back to your own viewmodel.

Grid Data Source

The grid supports 3 types of data sources:

  • source-type="local" - All the data is already present and you can give it to the grid immediatelly. The grid will provide filtering, pagination and sorting including multi-column filtering.
  • source-type="delegate" - The data retrival can be delegated to a function that will receive a callback with information about the page, sorting and filtering.
  • source-type="remote" - The data is retrieved from a remote URL. Filtering, pagination and sorting can be provided by the server.

Read the complete Data Source documentation for details on how each data source can be configured.

Grid Properties

  • source-page-sizes="[10, 25, 50]" - The list of paginations that should be available. WIP
  • columns-show-headers="true|false" - Flag to turn the grid headers on/off (default is true)
  • columns-can-sort="true|false" - Flag to turn the grid sorting on/off (default is true). You still need to turn on every column to be sortable!
  • columns-can-filter="true|false" - Flag to turn the grid filters on/off (default is false). WIP

Grid Pager

The grid provides its default pager that supports first/last, current page, incremental next/back pages, a page sizes selector and a grid summary. The visibiliy of each part of the pager can be configured through various flags. The pager can also be completly overwritten with your own custom pager.

Read the complete Grid Pager documentation for details on how the pager can be configured or customized.

Grid Selection

Grid Methods

<grid grid.ref="myGrid" ...>
...
</grid>

Then from your code you can call the grid to request a refresh. A refresh always maintains the current filters, pagination and sorting.

function doSomeWork(){
	this.myGrid.refresh();
}

Grid Icons

The grid is using by default the icons from font-awesome. All the icons are defined in the grid-icons.js file. You can replace the grid icons by setting a different grid.icons.

var myIcons = {
  refresh: "fa fa-refresh",
  sortingAsc: "fa fa-sort-asc text-primary",
  sortingDesc: "fa fa-sort-desc text-primary",
  firstPage: "fa fa-step-backward",
  firstPageTitle: "First page",
  prevPage: "fa fa-caret-left",
  prevPageTitle: "Previous page",
  nextPage: "fa fa-caret-right",
  nextPageTitle: "Next page",
  lastPage: "fa fa-step-forward",
  lastPageTitle: "Last page",
}
this.grid.icons = myIcons;

aurelia-grid's People

Contributors

corneliutusnea avatar fouriedewet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

aurelia-grid's Issues

Disabling pager - how to?

Hi,

Is there a way to completly disable the paging? I know there is pager.autoHide but it only work to show / hide the paging panel. The content keep being paged even if this option is set to true.

Thanks

Integration with aurelia-i18n ?

Hi,

Have anyone tried to use this component with aurelia-i18n value converters ? I did a quick test but it does not seem to work the way I thought it would (eg: <grid-col heading="${ 'key' | t }" ).

How to configure wit web pack.

Hi , I have tried to use your grid plugin on aurelia cli and for aurelia web pack. In the both the cases it is not working.

Please provide complete configration details for both webapack and cli

Does this work with webpack?

I installed it using npm
npm install aurelia-gri
and added it to my project using
.plugin('aurelia-grid')
also tried
.plugin('corneliutusnea/aurelia-grid')
but I'm getting a System not defined error. I believe it is erroring out on index.js. I have manually bootstrapped aurelia.

this.dataRead is not a function

It seems to me as if there's an error with delegated datasource implementation. Code in grid-delegated-source is referring to dataRead function that is not defined anywhere. Corresponding code in grid-local-source has these lines, that are missing from grid-delegate-source:

                this.dataRead = grid.sourceRead;
                if (!this.dataRead) {
                    throw new Error("'data-read.call' is not defined on the grid.");
                }

Anyway we could get a new jspm package?

Some serious issues have been fixed, and we really desperately need to those fixes. Right now I'm copying the code over the installed package code... is there a better way, or better, could we get a new package.

Binding to Parent viewmodel properties and function does not work - Solution

Hi,
Your current implementation deos not work when you try to bind a button in a grid-col to a function in the parent viewmodel like below:

          <grid-col can-sort="true" heading="Salary" field="salary" class="col-xs-3" can-filter="true">
            <button class="btn btn-info btn-xs" click.trigger="onItemClicked($item)">
              Transfer
            </button>
          </grid-col>

It errors out saying onItemClicked is not a function
Solution

  1. in grid.ts, change the bind function definition from
    bind(bindingContext) to bind(bindingContext, overrideContext)
  2. Change the last line in bind function from this.builder.build(); to this.builder.build(bindingContext, overrideContext);
  3. In grid-builder.ts, change the build function def from
    build() {
        // Listen for window resize so we can re-flow the grid layout
        this.resizeListener = window.addEventListener('resize', this.headersSyncColumnHeadersWithColumns.bind(this));

        this.buildHeadingTemplate();
        this.buildRowTemplate();
        this.buildPagerTemplate();
    }

to

    build(bindingContext, overrideContext) {
        // Listen for window resize so we can re-flow the grid layout
        this.resizeListener = window.addEventListener('resize', this.headersSyncColumnHeadersWithColumns.bind(this));

        this.buildHeadingTemplate(bindingContext, overrideContext);
        this.buildRowTemplate(bindingContext, overrideContext);
        this.buildPagerTemplate(bindingContext, overrideContext);
    }
  1. Still in grid-builder.ts, change the function definitions buildHeadingTemplate(), buildRowTemplate() and buildPagerTemplate() to buildHeadingTemplate(bindingContext, overrideContext), buildRowTemplate(bindingContext, overrideContext) and buildPagerTemplate(bindingContext, overrideContext) respectively. Then in each of the above functions, change the lines where you call view.bind() to
    view.bind(this.grid, overrideBindingContext); where overrideBindingContext is declared as
    let overrideBindingContext = {
      bindingContext: this.grid,
      parentOverrideContext: {
        bindingContext: bindingContext,
        parentOverrideContext: overrideContext
      }
    };

The variable overrideBindingContext creates like a cascade of context objects that will allow any functions and properties in the parent viewmodels to be reached (without using $parent) from within grid-column templates.

A PR would be in order but I don't yet do Typescript all my test was done on the transpilled code.
I hope this helps.

The motivation for this was the understanding I gained while reading your source code (beautiful code by the way. Your sense of organization is simply wonderful), which enabled me solve the same problem for charlespockert aurelia-bs-grid which this code is also based on.

Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.