Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Offer 'Raw Data' format besides 'Tabular View'. This is particularly useful for the rendering of a table as JSON for example with Views Datasource.
Comment | File | Size | Author |
---|---|---|---|
#24 | Manage display Drush Site Install (1).jpg | 112.82 KB | lolandese |
#24 | Basic page Site Install (1).jpg | 82.23 KB | lolandese |
#17 | raw_format-2847650-17.patch | 19.25 KB | lolandese |
#16 | errors.png | 185.47 KB | SebasL |
#16 | table-content.png | 45.41 KB | SebasL |
Comments
Comment #2
lolandese CreditAttribution: lolandese at HCL Technologies Limited commentedWork in progress.
Comment #3
lolandese CreditAttribution: lolandese at HCL Technologies Limited commentedAttached patch offers besides Tabular view:
Example (in pretty print)
Tabular view
Raw data (JSON)
Raw data (JSON) with header values as keys (if not empty)
If a header value is empty the original key is used. If for example in table above the column header value "C" would be empty then "col_2" would be used as key for that column.
Note
We only have pretty print output if on a node page thus in e.g. a View it will be without indentation and line breaks. Usually you would however only use the JSON display in a View capable of serving JSON of through the Services module and still use the Tabular view on the node page. That's why when in JSON mode options like 'Hide header' and 'CSV export' won't have effect.
Solving #2841782: Move display related settings from manage fields to manage display will become more relevant.
Comment #4
lolandese CreditAttribution: lolandese at HCL Technologies Limited commentedComment #5
lolandese CreditAttribution: lolandese at HCL Technologies Limited commentedAdded another display mode 'Raw data (JSON) with header and first column values as keys (if not empty)'. This gives us complete control over the used keys in the JSON on all levels.
Example (in pretty print
Tabular view
A
B
C
First
11
12
13
Second
21
22
23
31
32
33
Raw data (JSON) with header and first column values as keys (if not empty)
Comment #6
lolandese CreditAttribution: lolandese at HCL Technologies Limited commentedModified the last added display mode to 'Raw data (JSON) with field label, header and first column values as keys (if not empty)'. This gives us even control over the used top level key.
Furthermore is displays the caption only if not empty (for all Raw JSON displays).
Comment #7
SebasL CreditAttribution: SebasL at HCL Technologies Limited commentedWhile testing a scenario was found that could be considered a bug, but it isn't: If the content of the first column is same in multiple rows, the JSON output only prints one. See below images.
To avoid confusion it is recommended to show a notification to the user informing the exception.
More reading:
The names within an object SHOULD be unique:
https://tools.ietf.org/html/rfc7159#section-4
http://stackoverflow.com/a/23195243/1606702
Comment #8
lolandese CreditAttribution: lolandese at HCL Technologies Limited commentedI agree.
Comment #9
lolandese CreditAttribution: lolandese at HCL Technologies Limited commentedAvoid informal writing (use 'a table' instead of 'your table').
Comment #10
lolandese CreditAttribution: lolandese at HCL Technologies Limited commentedWith an empty table:
Warning: Invalid argument supplied for foreach() in tablefield_field_formatter_view() (line 525 of /sites/all/modules/contrib/tablefield/tablefield.module).
To wrap in a conditional, also in the other view mode (line 480).
Comment #11
lolandese CreditAttribution: lolandese at HCL Technologies Limited commentedPatch additions:
Comment #12
lolandese CreditAttribution: lolandese at HCL Technologies Limited commentedAgainst latest dev.
Comment #13
lolandese CreditAttribution: lolandese at HCL Technologies Limited commentedInstead of having 3 different view modes for raw JSON data we extended only one with different display options. The result is cleaner and shorter code while enhancing the user experience.
Furthermore we introduced the option to:
The latter is especially handy when dealing with long lists of key-value pairs that would otherwise be forced to be orientated horizontally resulting in a horizontal scrollbar, worsening the user experience. The setting is there but the feature of swapping should still be built.
Comment #14
lolandese CreditAttribution: lolandese at HCL Technologies Limited commentedAdded row-column swap option.
View mode:
Edit mode:
Display options:
Comment #15
lolandese CreditAttribution: lolandese at HCL Technologies Limited commentedComment #16
SebasL CreditAttribution: SebasL at HCL Technologies Limited commentedThe patch fails when there are more than one header or first column with same value.
Settings in error scenario:
Content in table:
Errors:
Comment #17
lolandese CreditAttribution: lolandese at HCL Technologies Limited commentedComment #18
lolandese CreditAttribution: lolandese at HCL Technologies Limited commentedComment #19
SebasL CreditAttribution: SebasL at HCL Technologies Limited commentedTest with equal and different column values, with all combination of settings.
The output is correct in all scenarios. Below screenshots of two scenarios:
Table with same value in multiple columns:
Settings in field:
Table output:
Different settings in field:
New table output:
Comment #21
lolandese CreditAttribution: lolandese at HCL Technologies Limited commentedThanks for the thorough review.
Comment #24
lolandese CreditAttribution: lolandese as a volunteer commentedCompare D8 (with just one option) with D7 below:
Comment #25
lolandese CreditAttribution: lolandese as a volunteer commentedNeeded would be probably also a D8 version of the Themeless module.