├── LICENSE
├── README.md
├── example
├── data.json
├── index.html
├── jquery.min.js
└── jsonTable.js
├── jsonTable.jquery.json
└── jsonTable.js
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2013 omkarkhair
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | this software and associated documentation files (the "Software"), to deal in
7 | the Software without restriction, including without limitation the rights to
8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 | the Software, and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | json Table
2 | =========
3 |
4 | A simple jQuery plugin to get your JSON data on a table.
5 |
6 | Gettings started
7 | ----------------
8 | You can use a table already attached to the DOM, or one you created in memory. jsonTable needs at least a thead with a tr, and a tbody. If they don't exist, they will be created.
9 |
10 | Initialize the table with the columns titles, and json identities to look for in the loaded file.
11 | ```javascript
12 | $("#dataTable").jsonTable({
13 | head : ['N.', 'Model','Operating System','Market Share'], // Goes on the
14 | json : ['*', 'model', 'name', 'share'] //json identities from the loaded json object
15 | }); // NOTE : an '*' identity will generate an autoincremented column
16 | ```
17 |
18 | The JSON data in this case looks something like this.
19 | ```json
20 | [
21 | {"model" : "Iphone 18", "name" : "iOS", "share" : 57.56},
22 | {"model" : "Nexus 23", "name" : "Android", "share" : 24.66},
23 | {"model" : "Tom-tom", "name" : "Java ME", "share" : 10.72},
24 | {"model" : "Nokia 66610", "name" : "Symbian", "share" : 2.49},
25 | {"model" : "Blackberry", "name" : "Blackberry", "share" : 2.26},
26 | {"model" : "Lumia", "name" : "Windows Phone", "share" : 1.33}
27 | ]
28 | ```
29 |
30 | Update the table from a JSON file. This could be the url to your JSON endpoint. Currently only GET requests are supported.
31 | ```javascript
32 | $("#dataTable").jsonTableUpdate("data.json");
33 | ```
34 |
35 | ####OR
36 |
37 | Update data from a JSON object.
38 | ```javascript
39 | $("#dataTable").jsonTableUpdate([
40 | {"id" : 1, "name" : "iOS", "share" : 57.56},
41 | {"id" : 2, "name" : "Android", "share" : 24.66},
42 | {"id" : 3, "name" : "Java ME", "share" : 10.72},
43 | {"id" : 4, "name" : "Symbian", "share" : 2.49},
44 | {"id" : 4, "name" : "Blackberry", "share" : 2.26},
45 | {"id" : 4, "name" : "Windows Phone", "share" : 1.33}
46 | ]);
47 | ```
48 |
--------------------------------------------------------------------------------
/example/data.json:
--------------------------------------------------------------------------------
1 | [
2 | {"model" : "Iphone 18", "name" : "iOS", "share" : 57.56},
3 | {"model" : "Nexus 23", "name" : "Android", "share" : 24.66},
4 | {"model" : "Tom-tom", "name" : "Java ME", "share" : 10.72},
5 | {"model" : "Nokia 66610", "name" : "Symbian", "share" : 2.49},
6 | {"model" : "Blackberry", "name" : "Blackberry", "share" : 2.26},
7 | {"model" : "Lumia", "name" : "Windows Phone", "share" : 1.33}
8 | ]
9 |
--------------------------------------------------------------------------------
/example/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/example/jsonTable.js:
--------------------------------------------------------------------------------
1 | (function ( $ ) {
2 |
3 | $.fn.jsonTable = function( options ) {
4 | var settings = $.extend({
5 | head: [],
6 | json:[]
7 | }, options, { table: this } );
8 |
9 | table = this;
10 |
11 | table.data("settings",settings);
12 |
13 | if (table.find("thead").length == 0) {
14 | table.append($("").append(""));
15 | }
16 |
17 | if (table.find("thead").find("tr").length == 0) {
18 | table.find("thead").append(" ");
19 | }
20 |
21 | if (table.find("tbody").length == 0) {
22 | table.append($("