🕷️ Crawler Inspector

URL Lookup

Direct Parameter Lookup

Raw Queries and Responses

1. Shard Calculation

Query:
Response:
Calculated Shard: 116 (from laksa008)

2. Crawled Status Check

Query:
Response:

3. Robots.txt Check

Query:
Response:

4. Spam/Ban Check

Query:
Response:

5. Seen Status Check

ℹ️ Skipped - page is already crawled

📄
INDEXABLE
CRAWLED
3 days ago
🤖
ROBOTS ALLOWED

Page Info Filters

FilterStatusConditionDetails
HTTP statusPASSdownload_http_code = 200HTTP 200
Age cutoffPASSdownload_stamp > now() - 6 MONTH0.1 months ago
History dropPASSisNull(history_drop_reason)No drop reason
Spam/banPASSfh_dont_index != 1 AND ml_spam_score = 0ml_spam_score=0
CanonicalPASSmeta_canonical IS NULL OR = '' OR = src_unparsedNot set

Page Details

PropertyValue
URLhttps://mshaeri.com/blog/flexitable-a-jquery-plugin-converting-dynamic-json-data-to-html-table/
Last Crawled2026-04-09 21:08:06 (3 days ago)
First Indexed2023-03-18 11:44:10 (3 years ago)
HTTP Status Code200
Meta TitleFlexiTable- A jQuery Plugin Converting Dynamic JSON With Nested Objects To HTML Table – A Developer Bird Blog
Meta Descriptionprofessional software developers blog. post about software engineering
Meta Canonicalnull
Boilerpipe Text
Post Views: 2,522 JSON or JavaScript Object Notation is a simple human readable data format that is mostly used to transfer/store data in web applications. It might happened in a project that you deal with JSON data received from back-end API, where you need to convert the data into an easy to read HTML table to display data for users. The problem comes when the JSON contains dynamic fields and nested objects that makes it difficult to parse the data and construct a table structure showing the data. For that purpose I developed a tiny plugin that generate HTML table of JSON data loaded from server. I put the In this article, I’ll be introducing Flexitable , a jQuery plugin that I developed recently to convert complex JSON data into an HTML table easily. Let’s get started. Assume we have following JSON array : [ {     "Id" : 1,     "Name" : "Alex Jeferson",     "Mathematics" : {         "S1" : 14,         "S2" : 18     },     "Chemistry" : {         "S1" : 19,         "S2" : 17     },     "Average" : 17 }, {     "Id" : 2,     "Name" : "Joe Mesh",     "Age" : 29,     "Mathematics" : {         "S1" : 10,         "S2" : 12     },     "Chemistry" : {         "S1" : 14,         "S2" : 18     },     "Average" : 15 } ] As you can see , records in the above JSON data contain fields Mathematics and Chemistry that their value are an Object instead of primitives. To show these kind of fields it is better to have parent and sub-header structure in order to make data easy to read and understandable. So, we need to display it in our front-end like below table : ID Name Mathematics Chemistry Average Semester 1 Semester 2 Semester 1 Semester 2 5005 Alex Jeferson 14 18 19 17 17 5016 Joe Mesh 10 12 14 18 15 With Flexitable it’s a peace of a cake to construct such tables. Let’s go to the point, the Flexitable . The Flexitable can be called on any container element such as Div to inject the desired table into it. It also can be called as stand alone function returning the Table DOM element : // Call Flexitable on a container to embed the table in the $("#targetDiv").flexiTable({...}); // Calling the Flexitable as a stand alone function var dataTable; $.flexiTable({...}).then((generatedTable) => { dataTable = generatedTable;}); Flexitable accepts Json as Javascript array and also it is able to fetch the JSON from a given URL : // calling Flexitable with a java script json array var jsonData = [{"id" : 1, "Name" : "Sam"}, {"id" : 2, "Name" : "Joe"}]; $("#targetDiv").flexiTable({ data : jsonData }); // calling Flexitable with a url var dataURL= "https://pathTOUrl.com/json"; $("#targetDiv").flexiTable({ data : dataURL }); You may need the table structure to place records cell vertically like below picture : Flexitable showing the json data with nested objects vertically Flexitable has solution for this need. put the verticalHeaders parameter in options : var jsonData = [{"id" : 1, "Name" : "Sam"}, {"id" : 2, "Name" : "Joe"}]; $("#targetDiv").flexiTable({ data : jsonData, verticalHeaders : true }); In case that you use the plugin to retrieve data from a URL, you can set a refresh period option in millisecond to retrieve the data periodically : var jsonData = [{"id" : 1, "Name" : "Sam"}, {"id" : 2, "Name" : "Joe"}]; $("#targetDiv").flexiTable({ data : jsonData, verticalHeaders : true, refreshPriod : 30000 }); The titles name can be customized by mapping their path to a name : var jsonData = [{"id" : 1, "Name" : "Joe", grade : { "Math" : 11, "Sport" : 15 }}, {"id" : 2, "Name" : "Sam", grade : { "Math" : 12, "Sport" : 18 }}]; $("#targetDiv").flexiTable({ data : jsonData, verticalHeaders : true, refreshPriod : 30000, columnsTitle : {'id' : 'Student ID', 'grade.Math' : 'Mathematics'} }); For fields containing an array, you can separate array items in the cell using arraySeparator : var jsonData = [{"id" : 1, "Name" : "Joe", absence: ["12th may", "5th jun"]}, {"id" : 2, "Name" : "Sam", absence: ["13th Sep", "1st May"]]; $("#targetDiv").flexiTable({ data : jsonData, verticalHeaders : true, refreshPriod : 30000, arraySeparator : ", " }); RTL or LTR direction of the table can be defined using rtl parameter : var jsonData = [{"id" : 1, "Name" : "Joe", absence: ["12th may", "5th jun"]}, {"id" : 2, "Name" : "Sam", absence: ["13th Sep", "1st May"]]; $("#targetDiv").flexiTable({ data : jsonData, verticalHeaders : true, refreshPriod : 30000, rtl : true }); Finally the Id and CSS class of the table : var jsonData = [{"id" : 1, "Name" : "Joe", absence: ["12th may", "5th jun"]}, {"id" : 2, "Name" : "Sam", absence: ["13th Sep", "1st May"]]; $("#targetDiv").flexiTable({ data : jsonData, verticalHeaders : true, refreshPriod : 30000, tableID : "reportTable", tableCssClass : "report colored" }); If you have JSON array of primitive type without key-value pair, the table sets header title for them by indexing staring from zero (0). Then you can choose a custom title for them using their index and columnsTitle paramter : var jsonData = [["Alex",12,13],["David",15,14],["Jone",13,11]]; $("#targetDiv").flexiTable({ data : jsonData, verticalHeaders : true, refreshPriod : 30000, columnsTitle : {'0' : 'Student Name', '1' : 'Mathematics', '2' : 'Sport'} }); At last but not the least, import the plugin in npm : npm i jqueryflexitable And in HTML page : <script src="jquery.flexitable.js" ></script> That’s it. Hope you find this jquery plugin useful. Thanks for reading. ☺
Markdown
[Skip to content](https://mshaeri.com/blog/flexitable-a-jquery-plugin-converting-dynamic-json-data-to-html-table/#content) April 6, 2026 [A Developer Bird Blog](https://mshaeri.com/blog/) - [Home](https://mshaeri.com/blog) - [Python](https://mshaeri.com/blog/category/programming/python/) - [Java](https://mshaeri.com/blog/category/programming/java/) - [Go](https://mshaeri.com/blog/category/programming/go/) - [AI](https://mshaeri.com/blog/category/computer-science/ai/) - [SQL](https://mshaeri.com/blog/category/programming/sql/) Menu - [Home](https://mshaeri.com/blog) - [Python](https://mshaeri.com/blog/category/programming/python/) - [Java](https://mshaeri.com/blog/category/programming/java/) - [Go](https://mshaeri.com/blog/category/programming/go/) - [AI](https://mshaeri.com/blog/category/computer-science/ai/) - [SQL](https://mshaeri.com/blog/category/programming/sql/) ![Flexitable.jquery.plugin.to.display.nested.json.object.dynamic.column](https://mshaeri.com/blog/wp-content/uploads/2023/01/Flexitable.jquery.plugin.to_.display.nested.json_.object.dynamic.column-1400x643.jpg) [ajax](https://mshaeri.com/blog/category/programming/javascript/ajax/) / [Computer Science](https://mshaeri.com/blog/category/computer-science/) / [html table](https://mshaeri.com/blog/category/programming/html-table/) / [JavaScript](https://mshaeri.com/blog/category/programming/javascript/) / [jQuery](https://mshaeri.com/blog/category/programming/jquery/) / [json](https://mshaeri.com/blog/category/programming/json/) / [Programming](https://mshaeri.com/blog/category/programming/) / [report](https://mshaeri.com/blog/category/programming/report/) # FlexiTable- A jQuery Plugin Converting Dynamic JSON With Nested Objects To HTML Table ![Bird](https://secure.gravatar.com/avatar/f5fa1621642de5439545f68c200e39d6?s=96&d=mm&r=g)by [Bird](https://mshaeri.com/blog/author/mostafa_shaeri_tj/) [January 21, 2023January 23, 2023](https://mshaeri.com/blog/flexitable-a-jquery-plugin-converting-dynamic-json-data-to-html-table/) Post Views: 2,522 JSON or JavaScript Object Notation is a simple human readable data format that is mostly used to transfer/store data in web applications. It might happened in a project that you deal with JSON data received from back-end API, where you need to convert the data into an easy to read HTML table to display data for users. The problem comes when the JSON contains dynamic fields and nested objects that makes it difficult to parse the data and construct a table structure showing the data. For that purpose I developed a tiny plugin that generate HTML table of JSON data loaded from server. I put the In this article, I’ll be introducing [Flexitable](https://github.com/birddevelper/FlexiTable), a jQuery plugin that I developed recently to convert complex JSON data into an HTML table easily. Let’s get started. Assume we have following JSON array : ``` [ {     "Id" : 1,     "Name" : "Alex Jeferson",     "Mathematics" : {         "S1" : 14,         "S2" : 18     },     "Chemistry" : {         "S1" : 19,         "S2" : 17     },     "Average" : 17 }, {     "Id" : 2,     "Name" : "Joe Mesh",     "Age" : 29,     "Mathematics" : {         "S1" : 10,         "S2" : 12     },     "Chemistry" : {         "S1" : 14,         "S2" : 18     },     "Average" : 15 } ] ``` As you can see , records in the above JSON data contain fields **Mathematics** and **Chemistry** that their value are an Object instead of primitives. To show these kind of fields it is better to have parent and sub-header structure in order to make data easy to read and understandable. So, we need to display it in our front-end like below table : | | | | | | | | |---|---|---|---|---|---|---| | ID | Name | Mathematics | Chemistry | Average | | | | Semester 1 | Semester 2 | Semester 1 | Semester 2 | | | | | 5005 | Alex Jeferson | 14 | 18 | 19 | 17 | 17 | | 5016 | Joe Mesh | 10 | 12 | 14 | 18 | 15 | With [Flexitable](https://github.com/birddevelper/FlexiTable) it’s a peace of a cake to construct such tables. Let’s go to the point, the **Flexitable**. The **Flexitable** can be called on any container element such as Div to inject the desired table into it. It also can be called as stand alone function returning the Table DOM element : ``` // Call Flexitable on a container to embed the table in the $("#targetDiv").flexiTable({...}); // Calling the Flexitable as a stand alone function var dataTable; $.flexiTable({...}).then((generatedTable) => { dataTable = generatedTable;}); ``` Flexitable accepts Json as Javascript array and also it is able to fetch the JSON from a given URL : ``` // calling Flexitable with a java script json array var jsonData = [{"id" : 1, "Name" : "Sam"}, {"id" : 2, "Name" : "Joe"}]; $("#targetDiv").flexiTable({ data : jsonData }); // calling Flexitable with a url var dataURL= "https://pathTOUrl.com/json"; $("#targetDiv").flexiTable({ data : dataURL }); ``` You may need the table structure to place records cell vertically like below picture : [![](https://m-shaeri.ir/blog/wp-content/uploads/2023/01/Flexitable.jquery.plugin.to_.display.nested.json_.object.dynamic-1024x308.jpg)](https://m-shaeri.ir/blog/wp-content/uploads/2023/01/Flexitable.jquery.plugin.to_.display.nested.json_.object.dynamic.jpg) Flexitable showing the json data with nested objects vertically Flexitable has solution for this need. put the verticalHeaders parameter in options : ``` var jsonData = [{"id" : 1, "Name" : "Sam"}, {"id" : 2, "Name" : "Joe"}]; $("#targetDiv").flexiTable({ data : jsonData, verticalHeaders : true }); ``` In case that you use the plugin to retrieve data from a URL, you can set a refresh period option in millisecond to retrieve the data periodically : ``` var jsonData = [{"id" : 1, "Name" : "Sam"}, {"id" : 2, "Name" : "Joe"}]; $("#targetDiv").flexiTable({ data : jsonData, verticalHeaders : true, refreshPriod : 30000 }); ``` The titles name can be customized by mapping their path to a name : ``` var jsonData = [{"id" : 1, "Name" : "Joe", grade : { "Math" : 11, "Sport" : 15 }}, {"id" : 2, "Name" : "Sam", grade : { "Math" : 12, "Sport" : 18 }}]; $("#targetDiv").flexiTable({ data : jsonData, verticalHeaders : true, refreshPriod : 30000, columnsTitle : {'id' : 'Student ID', 'grade.Math' : 'Mathematics'} }); ``` For fields containing an array, you can separate array items in the cell using arraySeparator : ``` var jsonData = [{"id" : 1, "Name" : "Joe", absence: ["12th may", "5th jun"]}, {"id" : 2, "Name" : "Sam", absence: ["13th Sep", "1st May"]]; $("#targetDiv").flexiTable({ data : jsonData, verticalHeaders : true, refreshPriod : 30000, arraySeparator : ", " }); ``` RTL or LTR direction of the table can be defined using rtl parameter : ``` var jsonData = [{"id" : 1, "Name" : "Joe", absence: ["12th may", "5th jun"]}, {"id" : 2, "Name" : "Sam", absence: ["13th Sep", "1st May"]]; $("#targetDiv").flexiTable({ data : jsonData, verticalHeaders : true, refreshPriod : 30000, rtl: true }); ``` Finally the Id and CSS class of the table : ``` var jsonData = [{"id" : 1, "Name" : "Joe", absence: ["12th may", "5th jun"]}, {"id" : 2, "Name" : "Sam", absence: ["13th Sep", "1st May"]]; $("#targetDiv").flexiTable({ data : jsonData, verticalHeaders : true, refreshPriod : 30000, tableID: "reportTable", tableCssClass : "report colored" }); ``` If you have JSON array of primitive type without key-value pair, the table sets header title for them by indexing staring from zero (0). Then you can choose a custom title for them using their index and **columnsTitle** paramter : ``` var jsonData = [["Alex",12,13],["David",15,14],["Jone",13,11]]; $("#targetDiv").flexiTable({ data : jsonData, verticalHeaders : true, refreshPriod : 30000, columnsTitle : {'0' : 'Student Name', '1' : 'Mathematics', '2' : 'Sport'} }); ``` At last but not the least, import the plugin in npm : ``` npm i jqueryflexitable ``` And in HTML page : ``` <script src="jquery.flexitable.js" ></script> ``` That’s it. Hope you find this jquery plugin useful. Thanks for reading. ☺ Tagged[convert](https://mshaeri.com/blog/tag/convert/)[html](https://mshaeri.com/blog/tag/html/)[java script](https://mshaeri.com/blog/tag/java-script/)[jquery](https://mshaeri.com/blog/tag/jquery/)[json](https://mshaeri.com/blog/tag/json/)[nested json object](https://mshaeri.com/blog/tag/nested-json-object/)[table](https://mshaeri.com/blog/tag/table/) ## Post navigation [Previous Post Previous post: Securing And Rate Limiting Endpoints With Spring Cloud Gateway, Spring Security And JWT](https://mshaeri.com/blog/securing-and-rate-limiting-endpoints-with-spring-cloud-gateway-spring-security-and-jwt/) [Next Post Next post: MockiMouse, Easy To Use Mock Server To Build Fake Dynamic API](https://mshaeri.com/blog/mockimouse-an-easy-to-use-mock-server-to-build-fake-dynamic-api/) ![](https://secure.gravatar.com/avatar/f5fa1621642de5439545f68c200e39d6?s=100&d=mm&r=g) #### Bird [View all posts by Bird →](https://mshaeri.com/blog/author/mostafa_shaeri_tj/ "Bird") ### You might also like [![Spring rest framework - SRF](https://mshaeri.com/blog/wp-content/uploads/2024/11/spring-rest-framework-445x265.jpg)](https://mshaeri.com/blog/spring-rest-framework-a-project-inspired-by-django-rest-framework/) ### [Spring Rest Framework (SRF) A Project Inspired by Django Rest Framework](https://mshaeri.com/blog/spring-rest-framework-a-project-inspired-by-django-rest-framework/ "Spring Rest Framework (SRF) A Project Inspired by Django Rest Framework") [December 8, 2024July 14, 2025](https://mshaeri.com/blog/spring-rest-framework-a-project-inspired-by-django-rest-framework/) [![Gradient Descent](https://mshaeri.com/blog/wp-content/uploads/2016/04/Gradient_Descent.jpg)](https://mshaeri.com/blog/gradient-descent-algorithm-for-linear-regression/) ### [Gradient Descent Algorithm for Linear Regression](https://mshaeri.com/blog/gradient-descent-algorithm-for-linear-regression/ "Gradient Descent Algorithm for Linear Regression") [April 1, 2016January 8, 2022](https://mshaeri.com/blog/gradient-descent-algorithm-for-linear-regression/) [![graphtea](https://mshaeri.com/blog/wp-content/uploads/2014/09/graphtea.jpg)](https://mshaeri.com/blog/learn-graph-theory-with-graphtea/) ### [Learn Graph Theory with GraphTea](https://mshaeri.com/blog/learn-graph-theory-with-graphtea/ "Learn Graph Theory with GraphTea") [September 17, 2014September 20, 2025](https://mshaeri.com/blog/learn-graph-theory-with-graphtea/) ### Leave a Reply [Cancel reply](https://mshaeri.com/blog/flexitable-a-jquery-plugin-converting-dynamic-json-data-to-html-table/#respond) #### Welcome I’m a software developer with a focus on web development, software architecture and database optimization. I occasionally share insights and practical tips from my work on this blog. **My projects on github :** - [*![](https://mshaeri.com/blog/wp-content/uploads/2026/01/python.png)* Dequest](https://github.com/birddevelper/dequest) - [*![](https://mshaeri.com/blog/wp-content/uploads/2026/01/python.png)* Azure IoTHub API](https://github.com/birddevelper/azure-iot-hub-api) - [*![](https://mshaeri.com/blog/wp-content/uploads/2021/11/springBoot.png)* Spring Rest Framework](https://github.com/nikanique/spring-rest-framework) - [*![](https://mshaeri.com/blog/wp-content/uploads/2025/01/django.png)* Django Query To Table](https://github.com/birddevelper/django-query-to-table) - [*![](https://mshaeri.com/blog/wp-content/uploads/2021/11/springBoot.png)* Salmos Report](https://github.com/birddevelper/salmos-report-spring-boot-starter) - [*![](https://mshaeri.com/blog/wp-content/uploads/2021/11/flask.png)* Flask Report](https://github.com/birddevelper/Flask_SqlAlchemy_Report) - [*![](https://mshaeri.com/blog/wp-content/uploads/2022/04/gologin.png)* GomoLogin](https://github.com/birddevelper/flexitable) - [*![](https://mshaeri.com/blog/wp-content/uploads/2021/11/jquery.png)* Flexitable](https://github.com/birddevelper/flexitable) - [*![](https://mshaeri.com/blog/wp-content/uploads/2023/01/mockimouse_mockserver.png)* MockiMouse Mock Server](https://github.com/birddevelper/mockimouse) #### Recent Posts - [Understanding RAG, Agentic AI, and MCP By a Real-World AI Assistant Example](https://mshaeri.com/blog/understanding-rag-agentic-ai-and-mcp-by-a-real-world-ai-assistant-example/) - [Speed Up Python With C Functions](https://mshaeri.com/blog/speed-up-python-with-c-functions/) - [Solving Azure Blob Trigger Delays by Switching to Event Grid](https://mshaeri.com/blog/azure-storage-blob-triggers-vs-event-grid-the-lesson-i-learned-in-production/) - [Make Python API Calls a Breeze with dequest Declarative Client](https://mshaeri.com/blog/make-python-api-calls-a-breeze-with-dequest-declarative-client/) - [Design Patterns I use in External API Integration in Python](https://mshaeri.com/blog/design-patterns-i-use-in-external-service-integration-in-python/) #### Recent Comments - [vans](https://open-claw.online/) on [Understanding RAG, Agentic AI, and MCP By a Real-World AI Assistant Example](https://mshaeri.com/blog/understanding-rag-agentic-ai-and-mcp-by-a-real-world-ai-assistant-example/#comment-2639) - Anthony Nguyen on [Design Patterns I use in External API Integration in Python](https://mshaeri.com/blog/design-patterns-i-use-in-external-service-integration-in-python/#comment-2573) - Angila on [Understanding RAG, Agentic AI, and MCP By a Real-World AI Assistant Example](https://mshaeri.com/blog/understanding-rag-agentic-ai-and-mcp-by-a-real-world-ai-assistant-example/#comment-2540) - [Bird](http://mshaeri.com/) on [Solving Azure Blob Trigger Delays by Switching to Event Grid](https://mshaeri.com/blog/azure-storage-blob-triggers-vs-event-grid-the-lesson-i-learned-in-production/#comment-2266) - Andrew Hill on [Solving Azure Blob Trigger Delays by Switching to Event Grid](https://mshaeri.com/blog/azure-storage-blob-triggers-vs-event-grid-the-lesson-i-learned-in-production/#comment-2252) #### Archives - [October 2025](https://mshaeri.com/blog/2025/10/) - [September 2025](https://mshaeri.com/blog/2025/09/) - [July 2025](https://mshaeri.com/blog/2025/07/) - [April 2025](https://mshaeri.com/blog/2025/04/) - [March 2025](https://mshaeri.com/blog/2025/03/) - [February 2025](https://mshaeri.com/blog/2025/02/) - [December 2024](https://mshaeri.com/blog/2024/12/) - [November 2024](https://mshaeri.com/blog/2024/11/) - [August 2024](https://mshaeri.com/blog/2024/08/) - [April 2024](https://mshaeri.com/blog/2024/04/) - [March 2024](https://mshaeri.com/blog/2024/03/) - [November 2023](https://mshaeri.com/blog/2023/11/) - [March 2023](https://mshaeri.com/blog/2023/03/) - [February 2023](https://mshaeri.com/blog/2023/02/) - [January 2023](https://mshaeri.com/blog/2023/01/) - [June 2022](https://mshaeri.com/blog/2022/06/) - [May 2022](https://mshaeri.com/blog/2022/05/) - [February 2022](https://mshaeri.com/blog/2022/02/) - [January 2022](https://mshaeri.com/blog/2022/01/) - [November 2021](https://mshaeri.com/blog/2021/11/) - [October 2021](https://mshaeri.com/blog/2021/10/) - [May 2021](https://mshaeri.com/blog/2021/05/) - [April 2021](https://mshaeri.com/blog/2021/04/) - [June 2020](https://mshaeri.com/blog/2020/06/) - [November 2019](https://mshaeri.com/blog/2019/11/) - [April 2016](https://mshaeri.com/blog/2016/04/) - [September 2014](https://mshaeri.com/blog/2014/09/) - [April 2014](https://mshaeri.com/blog/2014/04/) - [February 2014](https://mshaeri.com/blog/2014/02/) - [January 2014](https://mshaeri.com/blog/2014/01/) #### Categories Copyright © 2026 [A Developer Bird Blog](https://mshaeri.com/blog/ "A Developer Bird Blog"). Powered by [WordPress](https://wordpress.org/) and [Bam](https://themezhut.com/themes/bam/).
Readable Markdown
Post Views: 2,522 JSON or JavaScript Object Notation is a simple human readable data format that is mostly used to transfer/store data in web applications. It might happened in a project that you deal with JSON data received from back-end API, where you need to convert the data into an easy to read HTML table to display data for users. The problem comes when the JSON contains dynamic fields and nested objects that makes it difficult to parse the data and construct a table structure showing the data. For that purpose I developed a tiny plugin that generate HTML table of JSON data loaded from server. I put the In this article, I’ll be introducing [Flexitable](https://github.com/birddevelper/FlexiTable), a jQuery plugin that I developed recently to convert complex JSON data into an HTML table easily. Let’s get started. Assume we have following JSON array : ``` [ {     "Id" : 1,     "Name" : "Alex Jeferson",     "Mathematics" : {         "S1" : 14,         "S2" : 18     },     "Chemistry" : {         "S1" : 19,         "S2" : 17     },     "Average" : 17 }, {     "Id" : 2,     "Name" : "Joe Mesh",     "Age" : 29,     "Mathematics" : {         "S1" : 10,         "S2" : 12     },     "Chemistry" : {         "S1" : 14,         "S2" : 18     },     "Average" : 15 } ] ``` As you can see , records in the above JSON data contain fields **Mathematics** and **Chemistry** that their value are an Object instead of primitives. To show these kind of fields it is better to have parent and sub-header structure in order to make data easy to read and understandable. So, we need to display it in our front-end like below table : | | | | | | | | |---|---|---|---|---|---|---| | ID | Name | Mathematics | Chemistry | Average | | | | Semester 1 | Semester 2 | Semester 1 | Semester 2 | | | | | 5005 | Alex Jeferson | 14 | 18 | 19 | 17 | 17 | | 5016 | Joe Mesh | 10 | 12 | 14 | 18 | 15 | With [Flexitable](https://github.com/birddevelper/FlexiTable) it’s a peace of a cake to construct such tables. Let’s go to the point, the **Flexitable**. The **Flexitable** can be called on any container element such as Div to inject the desired table into it. It also can be called as stand alone function returning the Table DOM element : ``` // Call Flexitable on a container to embed the table in the $("#targetDiv").flexiTable({...}); // Calling the Flexitable as a stand alone function var dataTable; $.flexiTable({...}).then((generatedTable) => { dataTable = generatedTable;}); ``` Flexitable accepts Json as Javascript array and also it is able to fetch the JSON from a given URL : ``` // calling Flexitable with a java script json array var jsonData = [{"id" : 1, "Name" : "Sam"}, {"id" : 2, "Name" : "Joe"}]; $("#targetDiv").flexiTable({ data : jsonData }); // calling Flexitable with a url var dataURL= "https://pathTOUrl.com/json"; $("#targetDiv").flexiTable({ data : dataURL }); ``` You may need the table structure to place records cell vertically like below picture : [![](https://m-shaeri.ir/blog/wp-content/uploads/2023/01/Flexitable.jquery.plugin.to_.display.nested.json_.object.dynamic-1024x308.jpg)](https://m-shaeri.ir/blog/wp-content/uploads/2023/01/Flexitable.jquery.plugin.to_.display.nested.json_.object.dynamic.jpg) Flexitable showing the json data with nested objects vertically Flexitable has solution for this need. put the verticalHeaders parameter in options : ``` var jsonData = [{"id" : 1, "Name" : "Sam"}, {"id" : 2, "Name" : "Joe"}]; $("#targetDiv").flexiTable({ data : jsonData, verticalHeaders : true }); ``` In case that you use the plugin to retrieve data from a URL, you can set a refresh period option in millisecond to retrieve the data periodically : ``` var jsonData = [{"id" : 1, "Name" : "Sam"}, {"id" : 2, "Name" : "Joe"}]; $("#targetDiv").flexiTable({ data : jsonData, verticalHeaders : true, refreshPriod : 30000 }); ``` The titles name can be customized by mapping their path to a name : ``` var jsonData = [{"id" : 1, "Name" : "Joe", grade : { "Math" : 11, "Sport" : 15 }}, {"id" : 2, "Name" : "Sam", grade : { "Math" : 12, "Sport" : 18 }}]; $("#targetDiv").flexiTable({ data : jsonData, verticalHeaders : true, refreshPriod : 30000, columnsTitle : {'id' : 'Student ID', 'grade.Math' : 'Mathematics'} }); ``` For fields containing an array, you can separate array items in the cell using arraySeparator : ``` var jsonData = [{"id" : 1, "Name" : "Joe", absence: ["12th may", "5th jun"]}, {"id" : 2, "Name" : "Sam", absence: ["13th Sep", "1st May"]]; $("#targetDiv").flexiTable({ data : jsonData, verticalHeaders : true, refreshPriod : 30000, arraySeparator : ", " }); ``` RTL or LTR direction of the table can be defined using rtl parameter : ``` var jsonData = [{"id" : 1, "Name" : "Joe", absence: ["12th may", "5th jun"]}, {"id" : 2, "Name" : "Sam", absence: ["13th Sep", "1st May"]]; $("#targetDiv").flexiTable({ data : jsonData, verticalHeaders : true, refreshPriod : 30000, rtl: true }); ``` Finally the Id and CSS class of the table : ``` var jsonData = [{"id" : 1, "Name" : "Joe", absence: ["12th may", "5th jun"]}, {"id" : 2, "Name" : "Sam", absence: ["13th Sep", "1st May"]]; $("#targetDiv").flexiTable({ data : jsonData, verticalHeaders : true, refreshPriod : 30000, tableID: "reportTable", tableCssClass : "report colored" }); ``` If you have JSON array of primitive type without key-value pair, the table sets header title for them by indexing staring from zero (0). Then you can choose a custom title for them using their index and **columnsTitle** paramter : ``` var jsonData = [["Alex",12,13],["David",15,14],["Jone",13,11]]; $("#targetDiv").flexiTable({ data : jsonData, verticalHeaders : true, refreshPriod : 30000, columnsTitle : {'0' : 'Student Name', '1' : 'Mathematics', '2' : 'Sport'} }); ``` At last but not the least, import the plugin in npm : ``` npm i jqueryflexitable ``` And in HTML page : ``` <script src="jquery.flexitable.js" ></script> ``` That’s it. Hope you find this jquery plugin useful. Thanks for reading. ☺
Shard116 (laksa)
Root Hash10197841126852103316
Unparsed URLcom,mshaeri!/blog/flexitable-a-jquery-plugin-converting-dynamic-json-data-to-html-table/ s443