finanalyst / grav-plugin-datatables

Grav plugin shortcode to add in DataTables Jquery
MIT License
8 stars 2 forks source link

json support #2

Closed diomed closed 6 years ago

diomed commented 6 years ago

could this plugin support data from uploaded .json file?

finanalyst commented 6 years ago

The shortcode operates on the contents between the open and close tags. Shortcodes operate from inner to outer. So if we have [tag1][tag2]stuff[/tag2][/tag1] then tag2 is triggered first and its contents are then provided to tag1.

Consequently, [datatables]content[/datatables] will act on anything inside content that has the html element <table>...</table> within it. So, if content contains an inner shortcode that gets data from a json file and parses it into a <table>...</table> element, then the answer to your question might be: the plugin already handles json code.

For example, I developed the [datatable] shortcode to act as an outer wrapper to another shortcode plugin I developed called sqlite-shortcode. The sqlite file is a form of data held in a file inside the Grav structure. So one shortcode takes the data in one form and converts it to html, the outer shortcode puts the html table into a datatable.

However, I suspect that you are suggesting that the [datatable] plugin is modified to take json code.

It seems to me that this is not a good paradigm. Taking serialised data in one form (a json file), parsing it, then converting it into another serialised form (html snippet) seems to me to be a completely different functionality than exposing the DataTables jQuery plugin to a designer using GRAV.

There are complexities in dealing with json code that are unrelated to datatables. For example, what are the columns and what are the rows? What happens to absent data, that is a row does not have the same number (or more data) than all the other rows. How many columns are created. Datatables expects a rectangular table.

In a sense it is a bit like good programming: refactor code that provides separate functionality into a function/class/subroutine. I think of each shortcode as a subroutine.

So I would suggest that you look for a shortcode that pulls data from a json code and places it in a table. I haven't checked as I write, but I think there is a plugin on the downloads page that does this.

diomed commented 6 years ago

thank you, I will check into it. ☑️