Giter VIP home page Giter VIP logo

group.js's Introduction

Grouping

A library to streamline getting flat arrays to be displayed in a UI list view with sections and rows.

Frquently an array of data will need to be displayed in a UI list view with section and an index list. A lot of time the array will be transformed into a multi-dimensional array to get section titles, rows per section and index list. This has a lot of large allocations when resorting and search/filtering a list.

Basic usage

var group = new Group(data, ['type']);
var secondSectionFirstItem = group.item([1,0];

Methods

  • count
  • title
  • item

Sample Dataset

var data = [
    {type:10, date:new Date('2015/1/1')},
    {type:10, date:new Date('2015/1/1')},
    {type:10, date:new Date('2015/1/4')},
    {type:40, date:new Date('2015/1/1')},
    {type:20, date:new Date('2015/1/1')},
    {type:60, date:new Date('2015/1/1')},
    {type:10, date:new Date('2015/1/3')},
    {type:20, date:new Date('2015/1/3')},
    {type:30, date:new Date('2015/1/3')},
    {type:20, date:new Date('2015/1/3')},
];

Common usage

Sort and group on the type property

var group = new Group(data, ['type']);

get a count of all the groups

var groupCount = group.coun();

get the title of the second group

var title = group.title([1]);

get the item in the fifth group, first row

var item = group.item([4,0]);

Multiple levels of grouping/sorting

any number of properties can be sorted and grouped on.

var group = new Group(data, ['type', 'date']; //note: see custom sorting

Custom sorting

optionally pass in custom sorting methods.
In the example below, date requires a custom sorter.

var group = new Group(data, {
    date: function(a,b) {
        return a.getDate() - b.getDate();
    },
    type: function(a,b){
        return (a > b ? 1 : (a < b ? -1 : 0));
    }
});

get the item in the first group, first subgroup, second row

var item = group.items([0,0,1]);

See further examples in the index.html file.

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.