File tree Expand file tree Collapse file tree 1 file changed +37
-1
lines changed
Expand file tree Collapse file tree 1 file changed +37
-1
lines changed Original file line number Diff line number Diff line change 1- # serialize2json
1+ # Serialize2JSON
22Serialize 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+
You can’t perform that action at this time.
0 commit comments