jennschiffer / timbles.js

a very simple jQuery plugin for tables, made by the person who literally did not invent tables
MIT License
38 stars 4 forks source link

Loading data from JSON doesn't allow for data-value transformations #16

Closed edelooff closed 8 years ago

edelooff commented 8 years ago

Looking into making the test suite proposed in #14 more generic, I ran into a limitation: When loading table information from a JSON source, it is not possible to have the source data be the plain text content of the cell, and apply a transformation on that data before storing it as the cell's data-value.

This means that a simple case-folding operation to support case-insensitive sorting is currently not possible, which seems like an unfortunate oversight.

Currently. a function called dataFilter can be provided in the configuration, which to me sounds like it would affect the data-value attribute of the cell rather than the text content. Additionally, filter is perhaps not the best name for something that doesn't actually filter.

I propose adding two new attributes to the column configuration:

  1. textTransform which takes the JSON field value and generates the text content for the cell;
  2. valueTransform which takes the JSON field value and generates the data-value for the cell.

The current dataFilter could then be kept backwards compatible by making is equal to the textTransform.

This would be good for tests, but also users who have similar requirements for case-insensitive sorting (mine are solved by generating the HTML server-side, but loading from JSON, it would be a definite need).