Skip to content

Commit f1c2414

Browse files
authored
Update README.md
1 parent 2ea64e2 commit f1c2414

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

README.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,38 @@
1-
# serialize2json
1+
# Serialize2JSON
22
Serialize standatd HTML table to JSON string using data-* attributes.
3+
4+
# How to Implement and Configure:-
5+
For any table requires JSON serialization add class `json-table`
6+
* .json-table must contain following attribute `data-target="jQuerySelector"`
7+
* .json-table must defined `<tbody>` tag.
8+
* .json-table rows (tr tags) should define json attributes and respective value using html5 data-* attributes.
9+
* .json-table may include data-ignore attribute to specify which are all data attribute which required to exclude from serialization.
10+
* Inside java script call `SerializeHtmlToJson()`;
11+
12+
# Sample Code HTML:-
13+
<table class="json-table" data-target="#jsonData" data-ignore="sortable,attr3">
14+
<tbody>
15+
<tr data-attr1="1.1" data-attr2="2.1" data-attr3="3.1">
16+
<td>Column1.1</td>
17+
<td>Column2.1</td>
18+
</tr>
19+
<tr data-attr1="1.2" data-attr2="2.2" data-attr3="3.2" data-attr4="4.2" data-sortable="true">
20+
<td>Column1.2</td>
21+
<td>Column2.2</td>
22+
</tr>
23+
</tbody>
24+
</table>
25+
26+
# Output:-
27+
[
28+
{ "attr1" : "1.1", "attr2" : "2.1"},
29+
{ "attr1" : "1.2", "attr2" : "2.2", "attr4" : "4.2"}
30+
]
31+
32+
# Limitations:-
33+
If you need to extend this plugin for table plugins (other than DataTable) you may need to destroy plugins before calling function.
34+
35+
# Where Results stored:-
36+
Serialized JSON Output to set as value to jQuery control specified in `data-target = ""`;
37+
for example's case it's saved in object `$('#jsonData')`; can be retrieved with following code `$('#jsonData').val()`
38+

0 commit comments

Comments
 (0)