GithubHelp home page GithubHelp logo

markxxv / filtering.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from robertpainsi/filtering.js

0.0 0.0 0.0 886 KB

Faceted Filters

License: MIT License

JavaScript 2.03% TypeScript 97.97%

filtering.js's Introduction

filtering.js

> Under construction <

This library is currently usable but still under construction. The filtering algorithm is fully implemented but design and tests need improvement, and options and callbacks need to be added.

What is Filtering.js

Preview
(Source: readme-preview.html)

Difference to other libraries?

  • โšก fast
  • ๐Ÿœ <10kB small
  • ๐Ÿ† Supported by modern browsers using ES6 features. 1,2,3,4
  • ๐Ÿ‹๏ธ Lifting complex logic from the developer.
  • ๐Ÿ”‹ Parse filter structure and items directly from HTML.
  • ๐Ÿ”ฎ Info about how many items would be filtered. No more 0 results.
  • ๐Ÿ‘ช Works in Node and Browser environment.

Performance

Following tables illustrate the performance of the library measured on Desktop. The runtime is calculated by averaging 1.000 scenarios with various number of items, groups, and filters and also various number of checked filters.

100 items
filters \ groups 2 4 8
8 <1 ms <1 ms <1 ms
24 <1 ms <1 ms <1 ms
64 <1 ms <1 ms <1 ms
1.000 items
filters \ groups 2 4 8
8 2 ms 3 ms 10 ms
24 2 ms 3 ms 6 ms
64 2 ms 3 ms 5 ms

How to use?

The preferred way to add filtering functionality to your project is by using the FilteringFlow helper class. It handles adding and removing of checked/disabled classes for filters and filtered classes for items. All classes can be adapted to easily suite existing projects too.

A simple, out of the box example:

<div id="root">
    <div id="filtering">
        <div class="filtering-group" data-group-name="color">
            <div class="filtering-filter" data-filter-name="red">Red</div>
            <div class="filtering-filter" data-filter-name="blue">Blue</div>
        </div>
        <div class="filtering-group" data-group-name="size">
            <div class="filtering-filter" data-filter-name="small">Small</div>
            <div class="filtering-filter" data-filter-name="large">Large</div>
        </div>
    </div>

    <div id="items">
        <div id="item-1" class="filtering-item" data-filter-color="red" data-filter-size="small"></div>
        <div id="item-2" class="filtering-item" data-filter-color="blue" data-filter-size="large"></div>
    </div>
</div>

<script>
    const {FilteringFlow} = filteringjs;
    new FilteringFlow(document.querySelector('#root'));
</script>

That's it!

Parser

The Schema can be directly parsed from HTML. For this, the structure has to be built according to following rules. All class names can be adapted to suite existing projects. See above example, example.html, initialize-from-html.html or other examples.

  • Group element
    • .filtering-group
    • data-group-name="color"
    • Filter element
      • .filtering-filter
      • data-filter-name="red"
  • Item element
    • .filtering-item
    • data-filter-color="red"
      (the attribute name ends with the group name and is assigned the filter name)

API

! Filter

  • Trigger
  • Pre-filter

! API

  • Options
  • Result
  • Functions
  • Callbacks

filtering.js's People

Contributors

robertpainsi avatar

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.