lightswitch05 / table-to-json

Serializes HTML tables into JSON objects.
http://lightswitch05.github.io/table-to-json/
MIT License
756 stars 172 forks source link

[Feature suggestion] data-valuetype #14

Closed DJWassink closed 9 years ago

DJWassink commented 10 years ago

Maybe it is a good idea to add something like a data-valuetype attribute to the plugin so that you can parse the field for a specific type. Currently everything gets returned as a string and it would be awesome if we could set in the table what kind of a type a certain value is and that the json returned from the table tries to parse the value's by the supplied data-valuetype.

lightswitch05 commented 10 years ago

This could get really complicated. I would be more interested in adding some hooks to allow any needed data manipulation. That way we wouldn't have to worry about a gazillion different formats of dates, times, etc. I'm not sure if we would want to do this based on a cell or entire column. I guess both would be preferable. This could also be used to fulfill the requests we've had to get values from <input>'s. This definitely needs more discussion, table-to-json needs an object oriented re-write anyways. @imamathwiz & @Mottie do you guys have any input?

Mottie commented 10 years ago

The data-override attribute is already in place

But yes, there should be an option to extract out the desired data, maybe something similar to what tablesorter does with the textExtraction function which is an option that could contain functions defined to extract out the desired text.

baw commented 10 years ago

This is definitely a useful idea.

During a rewrite, we could also try to make it more extendable by allowing people to add plugins. This way users could add there own functionality without us having to make the library too bloated. Although, this might be a little overkill.

lightswitch05 commented 9 years ago

I've started a rewrite. The only functionality I don't have working yet is colspan. rowspan is working properly. I will probably be adding callback support to this rewrite as well.

Mottie commented 9 years ago

Hey @lightswitch05!

I added a textExtractor branch which should fix this issue and #16. I didn't merge it into the main just in case you wanted to tweak it some more.

The readme contains examples on how to use the new textExtractor option.

lightswitch05 commented 9 years ago

@Mottie thanks for getting this added! I'm fine with getting it merged and tagged for a new release. I'll need to port the functionality to the rewrite branch. It is very close be being completed, I just haven't figured out how to do colspan with the new design.

Mottie commented 9 years ago

I did look at the rewrite code, I think the reason it doesn't work is because it needs to process all the columns & rows first... so colspan and rowspan data can be set up, then process the ignore rows/columns.

I was going to work on it, but it's a bit convoluted, and the tabletojson-row.js and tabletojson-cell.js scripts need to be more tightly knit together.