1====== JSON Table Demo ====== 2 3This is example for the [[https://www.dokuwiki.org/plugin:jsontable|JSON Table Plugin]]. 4 5 6===== Simple example ===== 7<code> 8<jsontable id=cars path=cars options='{"colHeaders": ["Year", "Car", "Count"]}'>[ 9 ["2017", "Honda", 10], 10 ["2018", "Toyota", 20], 11 ["2019", "Nissan", 30] 12]</jsontable> 13</code> 14<jsontable id=cars_ path=cars options='{"colHeaders": ["Year", "Car", "Count"]}'>[ 15 ["2017", "Honda", 10], 16 ["2018", "Toyota", 20], 17 ["2019", "Nissan", 30] 18]</jsontable> 19 20 21===== Advanced example ===== 22 23==== Table data definition ==== 24Add som data into JSON_database.cars: 25<code> 26<json path=cars2>[ 27 ["BMW", 2017, {"color": {"chassis": "white", "bumper": "white"}}], 28 ["Renault", 2015, {"color": {"chassis": "yellow", "bumper": "black"}}], 29 ["Tesla", 2018, {"color": {"chassis": "red"}}] 30]</json> 31</code> 32<json path=cars2>[ 33 ["BMW", 2017, {"color": {"chassis": "white", "bumper": "white"}}], 34 ["Renault", 2015, {"color": {"chassis": "yellow", "bumper": "black"}}], 35 ["Tesla", 2018, {"color": {"chassis": "red"}}] 36]</json> 37 38 39==== Table options definition ==== 40Table options are basically JSON data and can be defined separately: 41<code> 42<json id=table_options_id path=table_options>{ 43 "colHeaders": ["Car", "Year", "Chassis color", "Bumper color"], 44 "columns": [ 45 {}, 46 {"type": "numeric"}, 47 { 48 "data": "2.color.chassis" 49 }, 50 { 51 "data": "2.color.bumper", 52 "width": 100, 53 "editor": "select", 54 "selectOptions": ["yellow", "red", "black", "white"] 55 } 56 ], 57 "search": true 58}</json> 59</code> 60<json id=table_options__id path=table_options>{ 61 "colHeaders": ["Car", "Year", "Chassis color", "Bumper color"], 62 "columns": [ 63 {}, 64 {"type": "numeric"}, 65 { 66 "data": "2.color.chassis" 67 }, 68 { 69 "data": "2.color.bumper", 70 "width": 100, 71 "editor": "select", 72 "selectOptions": ["yellow", "red", "black", "white"] 73 } 74 ], 75 "search": true 76}</json> 77 78 79===== Table ===== 80%%<jsontable>%% element is first handled by [[https://www.dokuwiki.org/plugin:json|JSON Data Plugin]]. Attributes 'options' and 'save' are specific. Here is description for all elements: 81 * ''id'' attribute is necessary, if we want to store changed data into dokuwiki document. This is handled by json plugin via safe ajax call. 82 * ''path'' attribute sets data source for table to previously generated data in JSON_database.cars. 83 * ''display'' attribute displays all tabs, just for info here. 84 * ''//inline_data//'' are json data, which are combined with 'original_data'. 'original_data' are already defined on path by previous %%<json>%% elements or by 'src' attribute. We can say, 'inline_data' overrides 'original_data'. 'combined_data' are 'inline_data' combined with 'original_data' and is passed to the table as initial value. In the example below, chassis.color is set to green for second car. Please note, that here we access array elements with object notation. 85 * ''save'' attribute specifies, how data are stored into ''//inline_data//''. If set to ''all'', then all 'combined_data' will be stored into 'inline_data' on table change. Otherwise only the difference form 'original data' will be saved. This is the default behavior. 86 * ''options'' attribute is a JSON string directly passed into [[https://handsontable.com/docs/6.2.2/Options.html|Handsontable options]]. 87 88<code> 89<jsontable id=cars2 path=cars2 display=all save=diff options=%$table_options%> 90{"1":{"2":{"color":{"chassis":"green"}}}} 91</jsontable> 92</code> 93<jsontable id=cars2_ path=cars2 display=all save=diff options=%$table_options%> 94{"1":{"2":{"color":{"chassis":"green"}}}} 95</jsontable> 96