Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9236883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:24:19+00:00 2026-06-18T07:24:19+00:00

I was trying to build a subgrid using jQGrid to show parent child relationship.

  • 0

I was trying to build a subgrid using jQGrid to show parent child relationship. I followed Manager and Employee relationships.
I am building a JSON at server and this is how it looks

{"total":1,"page":1,"records":20,
"rows":[{"id":"Mgr 001","EmpId":"Mgr 001","Manager Name":"Murali","Dept":"D1"
 ,"Employees":[{"EmpId":"Emp 100","Name":"Alex","Dept":"Infrastucture"}]}]

The problem is when i click on expand i am finding the data from
locally stored employeeLocalJSON variable and assigning the collection
to subgrid. But it was not shown in subgrid. I have no idea why it is
so. I want to load json from server and to show subgrid i should use
the same, so i stored that one in local variable employeeLocalJSON.

I followed jqgrid subgrids from a single nested json

jqGrid Subgrid with "local" Data

JqGrid with subgrid and single XML file as input

Here is my jQGrid code

$(function() {

var employeeLocalJSON;
jQuery("#list").jqGrid({
    //start
    url: '/Employee/Search',
    datatype: "json",
    postData: {
        searchModel: function () {
            var result = {}, i, item,
             formInfo = $('#search-form').serializeArray(),
             l = formInfo.length;
            for (i = 0; i < l; i++) {
                item = formInfo[i];
                result[item.name] = item.value;
            }
            return JSON.stringify(result);
        }
    },
    mtype: "POST",
    colNames: ['id', 'EmpId', 'Manager Name', 'Dept'],
    colModel: [
    { name: 'id', index: 'id', hidden: true, width: 1, align: 'left', key: true },
    { name: 'EmpId', index: 'EmpId', search: true, width: 260, align: 'left' },
    { name: 'ManagerName', index: 'ManagerName', search: false, width: 110, align: 'left' },
    { name: 'Dept', index: 'Dept', search: true, width: 54, align: 'left' }],
    pager: $("#pager"),
    rowNum: 20,
    rowList: [5, 10, 20, 50],
    sortname: 'EmpId',
    sortorder: "asc",
    viewrecords: true,
    loadonce: true,
    sortable: true,
    jsonReader: {
        repeatitems: false
    },
    loadComplete: function (data) {
        if (data.rows) {
            employeeLocalJSON = data.rows; // save original JSON data
        }
    },
    caption: 'Employee Manager Detail',
    subGrid: true,
    subGridOptions: {
        "plusicon": "ui-icon-triangle-1-e",
        "minusicon": "ui-icon-triangle-1-s",
        "openicon": "ui-icon-arrowreturn-1-e",
        "reloadOnExpand": false,
        "selectOnExpand": true
    },
    subGridRowExpanded: function (grid_id, row_id) {
        //            //start of subgrid row expanded
        var subgrid_table_id, pager_id;
        subgrid_table_id = grid_id + "_tone";
        pager_id = "pone_" + subgrid_table_id;
        $("#" + grid_id).html("<table id='" + subgrid_table_id + "' class='scroll' style='width:100%'></table><div id='" + pager_id + "' class='scroll'></div>");
        var indexes = $(this).jqGrid('getGridParam', '_index');

        var empList = employeeLocalJSON[indexes[row_id]].Employees;

        $("#" + subgrid_table_id).jqGrid({
            datatype: 'local',
            data: empList,
            colNames: ['EmpId', 'Name', 'Dept'],
            colModel: [
                        { name: 'EmpId', width: 170 },
                        { name: 'Name', width: 110 },
                        { name: 'Dept', width: 60 }
                       ],
            sortname: 'EmpId',
            viewrecords: true,
            sortorder: "asc",
            width: 960
        });
    }

    //end
});
//                         });
jQuery("#list").jqGrid('navGrid', '#pager', { add: false, edit: false, del: false });
});

How do i achieve loading sub grid from a single JSON? What could be wrong in my code? I am not able to see the subgrid, even i bound a data

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T07:24:21+00:00Added an answer on June 18, 2026 at 7:24 am

    The first important problem which you have is the usage of spaces in id values (see "id":"Mgr 001" in your data). I can suggest you two alternative to fix the problem. The first one will be to change the algorithm how you generate id values. For example you can just remove all spaces from the id if it is possible or replace " " to any other character. Another alternative will be to change the line of jqGrid code

    return String(sid).replace(/[!"#$%&'()*+,.\/:;<=>?@\[\\\]\^`{|}~]/g,"\\$&");
    

    to

    return String(sid).replace(/[!"#$%&'()* +,.\/:;<=>?@\[\\\]\^`{|}~]/g,"\\$&");
    

    (add space to the list of characters which should be encoded by jqGrid).

    To post subgrid information in one response together with the main grid data I suggest you to use userdata part of JSON which will be accessed later as "userData" (case is important !!!) parameter of jqGrid. If you can’t do this on the server side you can make the corresponding transformation of the server response inside of beforeProcessing callback. See the answer for the corresponding code example.

    UPDATED: I reminded Tony one more time (see here) about the suggestion to escape spaces in the id. Just now (see here) the change is included in the main code of jqGrid. So in the next version (higher as the current 4.4.3) jqGrid will work with ids having spaces.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to build dynamic output from json and using jq/template tmpl display rows/columns. Somehow
I am trying build a DataTable one row at a time using the following
Trying to build the following simple example #include <boost/python.hpp> using namespace boost::python; tuple head_and_tail(object
Trying to build a marquee control with smooth text animation. Current efforts include: Using
I am trying build a page, where a user can login using his google
Im trying to build and automated log in using Googles authSub, but I need
I'm trying build a conditions array to be using in a prepared statement: Cars.find(:all,
Im trying to build a little site using XML instead of a database. I
I'm trying build this network connection using BroadcastReceiver. When connection doesnt exist it will
Trying to build a Metro app using Javascript and having issues with IndexedDb. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.