Sibeesh Passion

Top Menu

  • Home
  • Search
  • About
  • Privacy Policy

Main Menu

  • Articles
    • Azure
    • .NET
    • IoT
    • JavaScript
    • Career Advice
    • Interview
    • Angular
    • Node JS
    • JQuery
    • Knockout JS
    • Jasmine Framework
    • SQL
    • MongoDB
    • MySQL
    • WordPress
  • Contributions
    • Medium
    • GitHub
    • Stack Overflow
    • Unsplash
    • ASP.NET Forum
    • C# Corner
    • Code Project
    • DZone
    • MSDN
  • Social Media
    • LinkedIn
    • Facebook
    • Instagram
    • Twitter
  • YouTube
    • Sibeesh Venu
    • Sibeesh Passion
  • Awards
  • Home
  • Search
  • About
  • Privacy Policy

logo

Sibeesh Passion

  • Articles
    • Azure
    • .NET
    • IoT
    • JavaScript
    • Career Advice
    • Interview
    • Angular
    • Node JS
    • JQuery
    • Knockout JS
    • Jasmine Framework
    • SQL
    • MongoDB
    • MySQL
    • WordPress
  • Contributions
    • Medium
    • GitHub
    • Stack Overflow
    • Unsplash
    • ASP.NET Forum
    • C# Corner
    • Code Project
    • DZone
    • MSDN
  • Social Media
    • LinkedIn
    • Facebook
    • Instagram
    • Twitter
  • YouTube
    • Sibeesh Venu
    • Sibeesh Passion
  • Awards
  • Linux Azure Function Isolated Dot Net 9 YAML Template Deployment

  • Build, Deploy, Configure CI &CD Your Static Website in 5 mins

  • Post Messages to Microsoft Teams Using Python

  • Get Azure Blob Storage Blob Metadata Using PowerShell

  • Deploy .net 6 App to Azure from Azure DevOps using Pipelines

JQWidgetsJQX Grid
Home›Products›JQWidgets›Implementing Nested Grid in JQWidget JQX Grid

Implementing Nested Grid in JQWidget JQX Grid

By SibeeshVenu
April 29, 2015
1462
0
Share:
Introduction
If you are new to JQwdget JQX Grid, I recommend you read my previous articles on the topic here.
  • Working With JQX Grid With Filtering And Sorting
  • Advanced JQX Grid With All Functionality

Today we will learn how to implement a nested grid using JQWidget JQX grid files.

Background

In my previous article I said all of the properties of JQwidget JQX grid and now we can implement them. Now I have a requirement to implement the Nested grid. So I thought of sharing that with you all.

Loading required files

To start, we need to load the necessary files first. Just select the files from the Solution Explorer and drag those to the last of body section of the page.

  1. <script type=“text/javascript” src=“jqwidgets/jqxcore.js”></script>
  2. <script type=“text/javascript” src=“jqwidgets/jqxdata.js”></script>
  3. <script type=“text/javascript” src=“jqwidgets/jqxbuttons.js”></script>
  4. <script type=“text/javascript” src=“jqwidgets/jqxscrollbar.js”></script>
  5. <script type=“text/javascript” src=“jqwidgets/jqxmenu.js”></script>
  6. <script type=“text/javascript” src=“jqwidgets/jqxgrid.js”></script>
  7. <script type=“text/javascript” src=“jqwidgets/jqxgrid.selection.js”></script>
  8. <script type=“text/javascript” src=“jqwidgets/jqxgrid.filter.js”></script>
  9. <script type=“text/javascript” src=“jqwidgets/jqxgrid.sort.js”></script>

Now it is time to load the CSS style sheet for the grid.

  1. <link href=“jqwidgets/styles/jqx.base.css” rel=“stylesheet” />

Once you have loaded the required files, we can start our implementation.

Before loading the JQWidget JQX grid, we need to understand the preceding terms.

  1. A Data Array: The main and the first necessary thing to load a grid is the data, we will provide a JSON array as data.
  2. A Source: Once the data is ready we will give this array to the source, where source is a JSON property on which we are giving some initial settings. We will look to it when implementing the grid.
  3. A Data Adapter: And once we have created the source element we will give this to another JSON property that is the same as the source with some different settings.
    Now we will start the grid implementation.

Implementing Grid

First we will load a simple grid, then we will implement the nested gird. Sounds good?

The simplest implementation to load a JQWidget JQX grid is as follows.

  1. $(“#jqxgrid”).jqxGrid(
  2. {
  3.     width: 850,
  4.     height: 365,
  5.     sortable: true,
  6.     source: source,
  7.     //rowdetails: true,  
  8.     rowsheight: 35,
  9.     //initrowdetails: initrowdetails,  
  10.     rowdetailstemplate: {
  11.         rowdetails: “<div id=’grid’ style=’margin: 10px;’></div>”,
  12.         rowdetailsheight: 220,
  13.         rowdetailshidden: true
  14.     },
  15.     ready: function() {
  16.         $(“#jqxgrid”).jqxGrid(‘showrowdetails’, 1);
  17.     },
  18.     columns: [{
  19.         text: ‘User Id’,
  20.         datafield: ‘UserId’,
  21.         hidden: true
  22.     }, {
  23.         text: ‘My Transactions’,
  24.         datafield: ‘TransactionName’
  25.     }]
  26. });

In the preceding code I knowingly commented two properties. Have you noticed it?

  1. //rowdetails: true,
  2. //initrowdetails: initrowdetails,

The preceding specified properties are the properties we need to assign for the nested grid.

We can set the data and assign it to the source as follows for the simple grid.

  1. var tdData = $.parseJSON(‘[{“UserId”: “5”,”TransactionName”: “TRAN-Chennai”},{“UserId”: “6”,”TransactionName”: “TRAN-Kerala”}]’);
  2. var source =
  3. {
  4.     datafields: [{
  5.         name: ‘UserId’,
  6.         type: ‘int’
  7.     }, {
  8.         name: ‘TransactionName’,
  9.         type: ‘string’
  10.     }],
  11.     id: ‘UserId’,
  12.     datatype: “array”,
  13.     async: false,
  14.     localdata: tdData
  15. };
  16. var ordersDataAdapter = new $.jqx.dataAdapter(ordersSource, {
  17.     autoBind: true
  18. });
  19. orders = ordersDataAdapter.records;

Now if you run the page you will get output as follows.

If your grid is not populated, please go to your browser console and check whether the required files are loaded correctly.

Now it is time to implement the nested grid.

Implementing the Nested Grid

So our new settings for the parent grid must be as follows.

  1. $(“#jqxgrid”).jqxGrid(
  2. {
  3.     width: 850,
  4.     height: 365,
  5.     sortable: true,
  6.     source: source,
  7.     rowdetails: true,
  8.     rowsheight: 35,
  9.     initrowdetails: initrowdetails,
  10.     rowdetailstemplate: {
  11.         rowdetails: “<div id=’grid’ style=’margin: 10px;’></div>”,
  12.         rowdetailsheight: 220,
  13.         rowdetailshidden: true
  14.     },
  15.     ready: function() {
  16.         $(“#jqxgrid”).jqxGrid(‘showrowdetails’, 1);
  17.     },
  18.     columns: [{
  19.         text: ‘User Id’,
  20.         datafield: ‘UserId’,
  21.         hidden: true
  22.     }, {
  23.         text: ‘My Transactions’,
  24.         datafield: ‘TransactionName’
  25.     }]
  26. });

And now we will create the function initrowdetails, you can see the code here.

  1. var nestedGrids = new Array();
  2. // create nested grid.  
  3. var initrowdetails = function(index, parentElement, gridElement, record)
  4. {
  5.     var id = record.uid.toString();
  6.     var grid = $($(parentElement).children()[0]);
  7.     nestedGrids[index] = grid;
  8.     var filtergroup = new $.jqx.filter();
  9.     var filter_or_operator = 1;
  10.     var filtervalue = id;
  11.     var filtercondition = ‘equal’;
  12.     var filter = filtergroup.createfilter(‘stringfilter’, filtervalue, filtercondition);
  13.     // fill the orders depending on the id.  
  14.     var ordersbyid = [];
  15.     for (var m = 0; m < orders.length; m++) {
  16.         var result = filter.evaluate(orders[m][“UserId”]);
  17.         if (result)
  18.         ordersbyid.push(orders[m]);
  19.     }
  20.     var secondaryDataFields = $.parseJSON(‘[{ “name”: “UserId”, “type”: “int” },{ “name”: “TransactionName”, “type”: “string” },{ “name”: “tranDate”, “type”: “string” },{ “name”: “tranUser”, “type”: “string” }]’);
  21.     var orderssource = {
  22.         datafields: secondaryDataFields,
  23.         id: ‘UserId’,
  24.         localdata: ordersbyid
  25.     }
  26.     var nestedGridAdapter = new $.jqx.dataAdapter(orderssource);
  27.     var secondaryGridColumn = $.parseJSON(‘[{ “text”: “User Id”, “datafield”:”UserId” , “hidden”:”true”},{ “text”: “Transaction Name”, “datafield”:”TransactionName” },{ “text”: “Transaction Date”, “datafield”:”tranDate” },{ “text”: “User”, “datafield”:”tranUser” }]’);
  28.     if (grid != null) {
  29.         grid.jqxGrid({
  30.             source: nestedGridAdapter,
  31.             width: 780,
  32.             height: 200,
  33.             columns: secondaryGridColumn
  34.         });
  35.     }
  36. }

You can see that the settings provided are the same as we provided for the parent grid and please note that the “id” in both of the sources are the same. We provide “UserId” as the key.

Complete Code

The following is the complete code.

  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <meta name=“viewport” content=“width=device-width” />
  5.         <link href=“jqwidgets/styles/jqx.base.css” rel=“stylesheet” />
  6.         <script type=“text/javascript” src=“jqwidgets/jquery-1.9.1.js”></script>
  7.         <script type=“text/javascript”>
  8.     $(document).ready(function() {
  9.     var tdData = $.parseJSON(‘[{“UserId”: “5”,”TransactionName”: “TRAN-Chennai”},{“UserId”: “6”,”TransactionName”: “TRAN-Kerala”}]’);
  10.     var source =
  11.     {
  12.         datafields: [{
  13.             name: ‘UserId’,
  14.             type: ‘int’
  15.         }, {
  16.             name: ‘TransactionName’,
  17.             type: ‘string’
  18.         }],
  19.         id: ‘UserId’,
  20.         datatype: “array”,
  21.         async: false,
  22.         localdata: tdData
  23.     };
  24.     var orderdetailsurl = $.parseJSON(‘[{“UserId”: “5”,”TransactionName”: “Adyar”,”tranDate”: “04/22/2015 1:35:52″,”tranUser”: “skannan”},{“UserId”: “5”,”TransactionName”: “Guindy”,”tranDate”: “04/22/2015 1:35:52″,”tranUser”: “skannan”},{“UserId”: “6”,”TransactionName”: “Trichur”,”tranDate”: “04/21/2015 1:46:50″,”tranUser”: “bmahadevan”}]’);
  25.     var secondGridData = $.parseJSON(‘[{ “name”: “UserId”, “type”: “int” },{ “name”: “TransactionName”, “type”: “string” },{ “name”: “tranDate”, “type”: “string” },{ “name”: “tranUser”, “type”: “string” }]’);
  26.     var ordersSource =
  27.     {
  28.         datafields: secondGridData,
  29.         datatype: “array”,
  30.         localdata: orderdetailsurl,
  31.         async: false
  32.     };
  33.     var ordersDataAdapter = new $.jqx.dataAdapter(ordersSource, {
  34.         autoBind: true
  35.     });
  36.     orders = ordersDataAdapter.records;
  37.     var nestedGrids = new Array();
  38.     // create nested grid.
  39.     var initrowdetails = function(index, parentElement, gridElement, record) {
  40.         var id = record.uid.toString();
  41.         var grid = $($(parentElement).children()[0]);
  42.         nestedGrids[index] = grid;
  43.         var filtergroup = new $.jqx.filter();
  44.         var filter_or_operator = 1;
  45.         var filtervalue = id;
  46.         var filtercondition = ‘equal’;
  47.         var filter = filtergroup.createfilter(‘stringfilter’, filtervalue, filtercondition);
  48.         // fill the orders depending on the id.
  49.         var ordersbyid = [];
  50.         for (var m = 0; m < orders.length; m++) {
  51.             var result = filter.evaluate(orders[m][“UserId”]);
  52.             if (result)
  53.             ordersbyid.push(orders[m]);
  54.         }
  55.         var secondaryDataFields = $.parseJSON(‘[{ “name”: “UserId”, “type”: “int” },{ “name”: “TransactionName”, “type”: “string” },{ “name”: “tranDate”, “type”: “string” },{ “name”: “tranUser”, “type”: “string” }]’);
  56.         var orderssource = {
  57.             datafields: secondaryDataFields,
  58.             id: ‘UserId’,
  59.             localdata: ordersbyid
  60.         }
  61.         var nestedGridAdapter = new $.jqx.dataAdapter(orderssource);
  62.         var secondaryGridColumn = $.parseJSON(‘[{ “text”: “User Id”, “datafield”:”UserId” , “hidden”:”true”},{ “text”: “Transaction Name”, “datafield”:”TransactionName” },{ “text”: “Transaction Date”, “datafield”:”tranDate” },{ “text”: “User”, “datafield”:”tranUser” }]’);
  63.         if (grid != null) {
  64.             grid.jqxGrid({
  65.                 source: nestedGridAdapter,
  66.                 width: 780,
  67.                 height: 200,
  68.                 columns: secondaryGridColumn
  69.             });
  70.         }
  71.     }
  72.     // creage jqxgrid
  73.     $(“#jqxgrid”).jqxGrid(
  74.     {
  75.         width: 850,
  76.         height: 365,
  77.         sortable: true,
  78.         source: source,
  79.         rowdetails: true,
  80.         rowsheight: 35,
  81.         initrowdetails: initrowdetails,
  82.         rowdetailstemplate: {
  83.             rowdetails: “
  84.             <div id=‘grid’ style=‘margin: 10px;’></div>“,
  85.             rowdetailsheight: 220,
  86.             rowdetailshidden: true
  87.         },
  88.         ready: function() {
  89.             $(“#jqxgrid”).jqxGrid(‘showrowdetails’, 1);
  90.         },
  91.         columns: [{
  92.             text: ‘User Id’,
  93.             datafield: ‘UserId’,
  94.             hidden: true
  95.         }, {
  96.             text: ‘My Transactions’,
  97.             datafield: ‘TransactionName’
  98.         }]
  99.     });
  100. });
  101. < /script>
  102.         <title>JQWidget JQX Nested Grip Implementation @ sibeeshpassion </title>
  103.     </head>
  104.     <body class=‘default’>
  105. JQWidget JQX Nested Grip Implementation @ sibeeshpassion
  106.         <br />
  107.         <div id=“jqxgrid”></div>
  108.         <script type=“text/javascript” src=“jqwidgets/jqxcore.js”></script>
  109.         <script type=“text/javascript” src=“jqwidgets/jqxdata.js”></script>
  110.         <script type=“text/javascript” src=“jqwidgets/jqxbuttons.js”></script>
  111.         <script type=“text/javascript” src=“jqwidgets/jqxscrollbar.js”></script>
  112.         <script type=“text/javascript” src=“jqwidgets/jqxmenu.js”></script>
  113.         <script type=“text/javascript” src=“jqwidgets/jqxgrid.js”></script>
  114.         <script type=“text/javascript” src=“jqwidgets/jqxgrid.selection.js”></script>
  115.         <script type=“text/javascript” src=“jqwidgets/jqxgrid.filter.js”></script>
  116.         <script type=“text/javascript” src=“jqwidgets/jqxgrid.sort.js”></script>
  117.     </body>
  118. </html>

Output

Now if things goes well, you will get output as follows.

Conclusion

I hope you liked this article. Please provide your valuable suggestions. It matters a lot. Please download the source code to learn more.

Point of interest

JQX Grid, JQWidget, JQX Nested Grid.

TagsImplementing Nested gridJQWidgetsJQX GridNested Grid
Previous Article

Working With Charts

Next Article

Drag and Drop the Legend and Maintain ...

0
Shares
  • 0
  • +
  • 0
  • 0
  • 0

SibeeshVenu

I am Sibeesh Venu, an engineer by profession and writer by passion. Microsoft MVP, Author, Speaker, Content Creator, Youtuber, Programmer.

Related articles More from author

  • Code SnippetsJQWidgetsJQX GridProducts

    Get jqwidget jqx grid column count

    June 19, 2015
    By SibeeshVenu
  • Working With JQX Grid With Filtering And Sorting And Searching
    JQWidgetsJQX Grid

    Working With JQX Grid With Filtering And Sorting And Searching

    November 29, 2014
    By SibeeshVenu
  • JQWidgetsJQX GridProducts

    Bind Json Data to JQWidget JQX Grid

    June 18, 2015
    By SibeeshVenu
  • Advanced JQX Grid With All Functionality
    JQueryJQWidgetsJQX GridProducts

    Advanced JQX Grid With All Functionality

    October 29, 2014
    By SibeeshVenu
  • Code SnippetsJQWidgetsJQX Grid

    Assign New Data Source To JQWidgets JQX Grid

    July 24, 2015
    By SibeeshVenu
  • Change Themes Dynamically In Grid
    JQWidgetsJQX GridProducts

    Change Themes Dynamically In Grid

    October 28, 2015
    By SibeeshVenu
0

My book

Asp Net Core and Azure with Raspberry Pi Sibeesh Venu

YouTube

MICROSOFT MVP (2016-2022)

profile for Sibeesh Venu - Microsoft MVP

Recent Posts

  • Linux Azure Function Isolated Dot Net 9 YAML Template Deployment
  • Build, Deploy, Configure CI &CD Your Static Website in 5 mins
  • Easily move data from one COSMOS DB to another
  • .NET 8 New and Efficient Way to Check IP is in Given IP Range
  • Async Client IP safelist for Dot NET
  • Post Messages to Microsoft Teams Using Python
  • Get Azure Blob Storage Blob Metadata Using PowerShell
  • Deploy .net 6 App to Azure from Azure DevOps using Pipelines
  • Integrate Azure App Insights in 1 Minute to .Net6 Application
  • Azure DevOps Service Connection with Multiple Azure Resource Group

Tags

Achievements (35) Angular (14) Angular 5 (7) Angular JS (15) article (10) Article Of The Day (13) Asp.Net (14) Azure (65) Azure DevOps (10) Azure Function (10) Azure IoT (7) C# (17) c-sharp corner (13) Career Advice (11) chart (11) CSharp (7) CSS (7) CSS3 (6) HighChart (10) How To (9) HTML5 (10) HTML5 Chart (11) Interview (6) IoT (11) Javascript (10) JQuery (82) jquery functions (9) JQWidgets (15) JQX Grid (17) Json (7) Microsoft (8) MVC (20) MVP (9) MXChip (7) News (18) Office 365 (7) Products (10) SQL (20) SQL Server (15) Visual Studio (10) Visual Studio 2017 (7) VS2017 (7) Web API (12) Windows 10 (7) Wordpress (9)
  • .NET
  • Achievements
  • ADO.NET
  • Android
  • Angular
  • Arduino
  • Article Of The Day
  • ASP.NET
  • Asp.Net Core
  • Automobile
  • Awards
  • Azure
  • Azure CDN
  • azure devops
  • Blockchain
  • Blog
  • Browser
  • C-Sharp Corner
  • C#
  • Career Advice
  • Code Snippets
  • CodeProject
  • Cognitive Services
  • Cosmos DB
  • CSS
  • CSS3
  • Data Factory
  • Database
  • Docker
  • Drawings
  • Drill Down Chart
  • English
  • Excel Programming
  • Exporting
  • Facebook
  • Fun
  • Gadgets
  • GitHub
  • GoPro
  • High Map
  • HighChart
  • How to
  • HTML
  • HTML5
  • Ignite UI
  • IIS
  • Interview
  • IoT
  • JavaScript
  • JQuery
  • jQuery UI
  • JQWidgets
  • JQX Grid
  • Json
  • Knockout JS
  • Linux
  • Machine Learning
  • Malayalam
  • Malayalam Poems
  • MDX Query
  • Microsoft
  • Microsoft ADOMD
  • Microsoft MVP
  • Microsoft Office
  • Microsoft Technologies
  • Microsoft Windows
  • Microsoft Windows Server
  • Mobile
  • MongoDB
  • Monthly Winners
  • MVC
  • MVC Grid
  • MySQL
  • News
  • Node JS
  • npm
  • Number Conversions
  • October 2015
  • Office 365
  • Office Development
  • One Plus
  • Outlook
  • Page
  • PHP
  • Poems
  • PowerShell
  • Products
  • Q&A
  • Raspberry PI
  • React
  • SEO
  • SharePoint
  • Skype
  • Social Media
  • Software
  • Spire.Doc
  • Spire.PDF
  • Spire.XLS
  • SQL
  • SQL Server
  • SSAS
  • SSMS
  • Storage In HTML5
  • Stories
  • Third Party Software Apps
  • Tips
  • Tools
  • Translator Text
  • Uncategorized
  • Unit Testing
  • UWP
  • VB.Net
  • Videos
  • Virtual Machine
  • Visual Studio
  • Visual Studio 2017
  • Wamp Server
  • Web API
  • Web Platform Installer
  • Webinars
  • WebMatrix
  • Windows 10
  • Windows 7
  • Windows 8.1
  • Wordpress
  • Writing

ABOUT ME

I am Sibeesh Venu, an engineer by profession and writer by passion. Microsoft MVP, Author, Speaker, Content Creator, Youtuber, Programmer. If you would like to know more about me, you can read my story here.

Contact Me

  • info@sibeeshpassion.com

Pages

  • About
  • Search
  • Privacy Policy
  • About
  • Search
  • Privacy Policy
© Copyright Sibeesh Passion 2014-2025. All Rights Reserved.
Go to mobile version