{"id":17579051,"url":"https://github.com/mlms13/rr-sortable-table","last_synced_at":"2026-01-08T06:04:43.482Z","repository":{"id":44041528,"uuid":"222812347","full_name":"mlms13/rr-sortable-table","owner":"mlms13","description":"A generically sortable table with ReasonReact and lenses-ppx","archived":false,"fork":false,"pushed_at":"2023-01-07T11:56:20.000Z","size":1176,"stargazers_count":8,"open_issues_count":9,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-04T17:53:22.326Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Reason","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mlms13.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-11-19T23:51:51.000Z","updated_at":"2024-11-05T00:36:51.000Z","dependencies_parsed_at":"2023-02-07T02:16:55.276Z","dependency_job_id":null,"html_url":"https://github.com/mlms13/rr-sortable-table","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlms13%2Frr-sortable-table","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlms13%2Frr-sortable-table/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlms13%2Frr-sortable-table/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlms13%2Frr-sortable-table/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mlms13","download_url":"https://codeload.github.com/mlms13/rr-sortable-table/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246215816,"owners_count":20741894,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-22T00:43:25.485Z","updated_at":"2026-01-08T06:04:43.406Z","avatar_url":"https://github.com/mlms13.png","language":"Reason","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Reason React Sortable Table\n\nThis is an exploration in making a generic Reason React table component. Each row is of some type `'a` (which is probably some product type like a record, but really could be anything). Columns are also defined in a list.\n\nEach column:\n\n- has a title\n- uses the title as its React key, but allows overriding the key to avoid collisions\n- knows how to extract a value from the row data type\n- knows how to render values of that type\n- optionally knows how to order values of that type, which will make the column sortable\n\nNormally, this would mean that a column is polymorphic (it extracts and renders different types of values from the row data), but that would make it difficult to provide a `list(column('a))` because each column would need to operate on the same type of cell data. Instead, `column` is defined as a GADT with an existential type, so your sort and render functions are type-safe, even though that type isn't represented in the column type.\n\n## Usage\n\nOf note, this is intended to be a source of inspiration more than a ready-to-use library. At the moment, I'm not planning on packaging this up and releasing it on npm, but if you're already using Material UI and want a simple sortable table component, usage looks like this:\n\n```reason\nopen Relude.Globals;\nopen BsAbstract;\n\ntype role = Admin | User;\n\nlet roleToString =\n  fun\n  | Admin =\u003e \"Admin\"\n  | User =\u003e \"User\";\n\ntype user = {\n  id: string,\n  name: string,\n  roles: list(role),\n  birthday: option(Js.Date.t),\n};\n\nlet rows = [ /* include user records here... */ ];\n\nlet columns = [\n  SortableTable.orderedColumn(\n    (module String.Ord),\n    ~title=\"Name\",\n    ~render=React.string,\n    user =\u003e user.name,\n  ),\n  SortableTable.unorderedColumn(\n    ~title=\"Roles\",\n    ~render=\n      roles =\u003e\n        roles\n        |\u003e List.map(roleToString)\n        |\u003e List.String.joinWith(\", \")\n        |\u003e React.string,\n    user =\u003e user.roles,\n  ),\n  SortableTable.orderedColumn(\n    (module Option.Ord(JsDate.Ord)),\n    ~title=\"Birthday\",\n    ~render=bd =\u003e Option.fold(\"-\", Js.Date.toString, bd) |\u003e React.string,\n    user =\u003e user.birthday,\n  )\n];\n\n[@react.component]\nlet make = () =\u003e \u003cSortableTable makeRowKey={user =\u003e user.id} rows columns /\u003e;\n```\n\nThe above example assumes you're using the [Relude](https://github.com/reazen/relude) + [bs-abstract](https://github.com/Risto-Stevcev/bs-abstract) libraries. The implementation of `SortableTable` in this project asks orderable columns be constructed with an `Ord` module for the corresponding data type. bs-abstract provides these `Ord` modules for many common types.\n\nBut if Relude and bs-abstract aren't your cup of tea, that's fine -- the implementation could absolutely use a \"normal\" `('a, 'a) =\u003e int` function for ordering instead, as is common in the OCaml world. Feel free to hack up this idea until it works for your needs.\n\nEarlier versions relied on [lenses-ppx](https://github.com/Astrocoders/lenses-ppx/) to generate the getters for each column. That has since been simplified away, but the ppx is still very useful, as you can see [in the example](https://github.com/mlms13/rr-sortable-table/tree/master/examples/users).\n\n## Limitations\n\n- Internally, we track the currently-sorted column by its `string` key. This is a bit sad, but since React already complains if you don't provide a unique key, this is a much easier option than requiring the outside world to provide a \"column eq\" function.\n- Material UI may not be for everyone. This approach could be modified to work with basically any table rendering. I happened to pick Material UI because it's easy enough and I didn't want to write CSS.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmlms13%2Frr-sortable-table","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmlms13%2Frr-sortable-table","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmlms13%2Frr-sortable-table/lists"}