• This repository has been archived on 07/Sep/2018
  • Stars
    star
    284
  • Rank 145,616 (Top 3 %)
  • Language
    Elm
  • License
    BSD 3-Clause "New...
  • Created over 8 years ago
  • Updated about 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Sortable tables for whatever data you want to display

DEPRECATED

This package is not published in 0.19 and above. In an effort to prune my responsibilities, we suggested that community members fork it and take it in the direction that makes sense to them. Maybe that means adding more features. Maybe it means removing things to make it even simpler. Maybe it means rewriting it from scratch. Point is, please search for packages with the same or similar name, and look for an author you trust.



What follows is the README from before in case you are curious about the history.



Sortable Tables

Create sortable tables for data of any shape.

This library also lets you customize <caption>, <tbody>, <tr>, etc. for your particular needs. So it is pretty easy to do whatever crazy CSS trickery is needed to get the exact table you want.

Examples

  1. U.S. Presidents by Birth Place / Code
  2. Travel Planner for the Mission District in San Francisco / Code

Usage Rules

  • Always put Table.State in your model.
  • Never put Table.Config in your model.

One of the core rules of The Elm Architecture is never put functions in your Model or Msg types. It may cost a little bit of extra code to model everything as data, but the architecture and debugging benefits are worth it. Point is, a Table.Config value is really just a bunch of view functions, so it does not belong in your model. It goes in your view!

Furthermore, you do not want to be creating table configurations dynamically, partly because it is harder to optimize. If you need multiple table configurations, it is best to create multiple top-level definitions and switch between them in your view based on other data in your Model. If your use case is so complex that this is not possible, please open an issue explaining your situation!

About API Design

This library is one of the first “reusable view” packages that also manages some state, so I want to point out some design considerations that will be helpful in general.

The Elm Architecture

It may not be obvious at first glance, but this library follows The Elm Architecture:

  • Model — There is a model named Table.State.

  • init — You initialize the model with Table.initialSort.

  • view — You turn the current state into HTML with Table.view.

  • update — This is a little hidden, but it is there. When you create a Table.Config, you provide a function Table.State -> msg so that whoever is rendering the table has a chance to update the table state.

I took some minor liberties with update to make the API a bit simpler. It would be more legit if Table.Config took a Table.Msg -> msg argument and you needed to use Table.update : Table.Msg -> Table.State -> Table.State to deal with it. I decided not to go this route because Table.Msg and Table.State would both allocate the same amount of memory and one version the overall API a bit tougher. As we learn from how people use this, we may see that the explicit update function is actually a better way to go though!

Single Source of Truth

The data displayed in the table is given as an argument to view. To put that another way, the Table.State value only tracks the details specific to displaying a sorted table, not the actual data to appear in the table. This is the most important decision in this whole library. This choice means you can change your data without any risk of the table getting out of sync. You may be adding things, changing entries, or whatever else; the table will never “get stuck” and display out of date information.

To make this more clear, let’s imagine the alternate choice: instead of giving List data to view, we have it live in Table.State. Now say we want to update the dataset. We grab a copy of the data, make the changes we want, and put it back. But what if we forget to put it back? What if we hold on to that second copy in our Model? Which one is the real data now?

Point is, when creating an API like this, own as little state as possible. Having multiple copies of “the same” value in your Model is a sure way to create synchronization errors. Elm is built on the idea that there should be a single source of truth, but if you design your API poorly, you can force your users to make duplicates and open themselves up to bugs for no reason. Do not do that to them!

Simple By Default

I designed this library to have a very smooth learning curve. As you read the docs, you start with the simplest functions. Predefined columns, and very little customization. This makes it easier for the reader to build a basic intuition for how things work.

The trick is that all these simple functions are defined in terms of crazier ones that allow for more customization. As the user NEEDS that complexity, they can read on and gradually use the parts that are relevant to them. This means the user never finds themselves in a situation where they have to learn a bunch of stuff that does not actually matter to them. At the same time, that stuff is there when they need it.

To turn this into advice about API design, helper functions can make a library simpler to learn and use. Ultimately, people may not use Table.floatColumn very often in real stuff, but that function is crucial for learning. So when you find yourself with a tough API, one way to ramp people up is to create specialized helper functions that let you get common functionality without confronting people with all the details.

More Repositories

1

elm-architecture-tutorial

How to create modular Elm code that scales nicely with your app
Elm
4,171
star
2

elm-todomvc

The TodoMVC app written in Elm, nice example for beginners.
Elm
1,220
star
3

start-app

DEPRECATED. Moved to elm-lang/html
Elm
392
star
4

elm-html

DEPRECATED. Moved to elm-lang/html
Elm
336
star
5

guide.elm-lang.org

My book introducing you to Elm!
Elm
318
star
6

functional-programming-in-elm

DRAFT outlining some techniques of functional programming
Shell
230
star
7

airplane-mode

Airplanes are programming heaven. Airplane Mode turns off the bad internet. Yes docs, no facebook!
Python
122
star
8

url-parser

Parse URLs into nicely structured data
Elm
114
star
9

elm-playground

Create pictures, animations, and games with Elm!
Elm
107
star
10

elm-html-and-js

Example of how to integrate Elm with HTML and JS
HTML
93
star
11

react-angular-ember-elm-performance-comparison

Comparing performance of Elm, React, Angular, and Ember
JavaScript
91
star
12

elm-http

DEPRECATED. This library is now called elm-lang/http
Elm
89
star
13

elm-markdown

Markdown parsing within Elm
Elm
88
star
14

first-person-elm

First-person navigation in a simple 3D world, written in Elm
Elm
85
star
15

focus

A library for getting and setting values in deeply nested data structures.
Elm
80
star
16

TodoFRP

Basic Todo list example, written with FRP in Elm
Elm
75
star
17

elm-graphics

The graphical building blocks that inspired Elm in the first place
Elm
55
star
18

elm-effects

DEPRECATED. Moved to elm-lang/core
Elm
46
star
19

automaton

experimental library for Arrowized FRP in Elm
Elm
41
star
20

elm-svg

DEPRECATED. Moved to elm-lang/svg
Elm
30
star
21

elm-syntax-highlighting

Syntax Highlighting for Elm in Sublime Text
30
star
22

time-zone-proposal

A proposal for accurately computing local time in JavaScript
29
star
23

elm-hack-night

Elm
28
star
24

virtual-dom

DEPRECATED. Full rewrite in elm-lang/virtual-dom
JavaScript
25
star
25

elm-format-on-save

Sublime Text plugin to run elm-format on save
Python
23
star
26

local-channel

Helps you write self-contained components in Elm
Elm
16
star
27

elm-project-survey

How do build times and asset sizes change as Elm projects grow larger?
Haskell
13
star
28

task-tutorial

Friendly functions for getting started with tasks
JavaScript
11
star
29

elm-at-strangeloop

6
star
30

elm-at-mloc-js

Slides and resources from the mloc.js conference in Budapest! Graciously hosted by Prezi :)
5
star
31

elm-at-pldi-2013

A presentation written entirely in Elm, made for a talk at PLDI 2013.
Elm
4
star
32

codemesh-tutorial

self-contained exercises that emphasize fundamentals and the Elm Architecture
JavaScript
4
star
33

cufp-tutorial

Practice problems for the Elm tutorial at CUFP 2014
Elm
2
star