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 6959295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:15:11+00:00 2026-05-27T15:15:11+00:00

JSON { mypage:{ outerwrapper:{ page:1, total:3, records:15, innerwrapper:{ rows:[ { id:1, read: true, cells:

  • 0

JSON

{
   "mypage":{
      "outerwrapper":{
         "page":"1",
         "total":"3",
         "records":"15",
         "innerwrapper":{
            "rows":[
               {
                  "id":"1",
                  "read": true,
                  "cells": [
                     {
                         "label":"linkimg",
                         "value": "Link-A",
                         "links": [
                             {
                                 "name":"link1"
                             },
                             {
                                 "name":"link2"
                             },
                             {
                                 "name":"link3"
                             }
                         ]
                     }
                  ]
               },
               {
                  "id":"2",
                  "read": false,
                  "cells": [
                     {
                        "label":"linkimg",
                        "value": "Link-B",
                        "links": [
                           {
                              "name":"link1"
                           },
                           {
                              "name":"link2"
                           }
                        ]
                     }
                  ]
               },
               {
                  "id":"3",
                  "read": false,
                  "cells": [
                     {
                        "label":"linkimg",
                        "value": "Link-C",
                        "links": [
                           {
                              "name":"link1"
                           },
                           {
                              "name":"link2"
                           }
                        ]
                     }
                  ]
               },
               {
                  "id":"4",
                  "read": false,
                  "cells": [
                     {
                        "label":"linkimg",
                        "value": "Link-D",
                        "links": [
                           {
                              "name":"link1"
                           },
                           {
                              "name":"link2"
                           }
                        ]
                     }
                  ]
               },
               {
                  "id":"5",
                  "read": false,
                  "cells": [
                     {
                        "label":"linkimg",
                        "value": "Link-E",
                        "links": [
                           {
                              "name":"link1"
                           },
                           {
                              "name":"link2"
                           }
                        ]
                     }
                  ]
               },
               {
                  "id":"6",
                  "read": false,
                  "cells": [
                     {
                        "label":"linkimg",
                        "value": "Link-F",
                        "links": [
                           {
                              "name":"link1"
                           },
                           {
                              "name":"link2"
                           }
                        ]
                     }
                  ]
               },
               {
                  "id":"7",
                  "read": false,                  
                  "cells": [
                     {
                        "label":"linkimg",
                        "value": "Link-G",
                        "links": [
                           {
                              "name":"link1"
                           },
                           {
                              "name":"link2"
                           }
                        ]
                     }
                  ]
               },
               {
                  "id":"8",
                  "read": false,                  
                  "cells": [
                     {
                        "label":"linkimg",
                        "value": "Link-H",
                        "links": [
                           {
                              "name":"link1"
                           },
                           {
                              "name":"link2"
                           }
                        ]
                     }
                  ]
               },
               {
                  "id":"9",
                  "read": false,
                  "cells": [
                     {
                        "label":"linkimg",
                        "value": "Link-I",
                        "links": [
                           {
                              "name":"link1"
                           },
                           {
                              "name":"link2"
                           }
                        ]
                     }
                  ]
               },
               {
                  "id":"10",
                  "read": false,
                  "cells": [
                     {
                        "label":"linkimg",
                        "value": "Link-J",
                        "links": [
                           {
                              "name":"link1"
                           },
                           {
                              "name":"link2"
                           }
                        ]
                     }
                  ]
               },
               {
                  "id":"11",
                  "read": false,
                  "cells": [
                     {
                        "label":"linkimg",
                        "value": "Link-K",
                        "links": [
                           {
                              "name":"link1"
                           },
                           {
                              "name":"link2"
                           }
                        ]
                     }
                  ]
               },
               {
                  "id":"12",
                  "read": false,
                  "cells": [
                     {
                        "label":"linkimg",
                        "value": "Link-L",
                        "links": [
                           {
                              "name":"link1"
                           },
                           {
                              "name":"link2"
                           }
                        ]
                     }
                  ]
               },
               {
                  "id":"13",
                  "read": false,
                  "cells": [
                     {
                        "label":"linkimg",
                        "value": "Link-M",
                        "links": [
                           {
                              "name":"link1"
                           },
                           {
                              "name":"link2"
                           }
                        ]
                     }
                  ]
               },
               {
                  "id":"14",
                  "read": false,
                  "cells": [
                     {
                        "label":"linkimg",
                        "value": "Link-N",
                        "links": [
                           {
                              "name":"link1"
                           },
                           {
                              "name":"link2"
                           }
                        ]
                     }
                  ]
               },
               {
                  "id":"15",
                  "read": true,
                  "cells": [
                     {
                        "label":"linkimg",
                        "value": "Link-O",
                        "links": [
                           {
                              "name":"link1"
                           },
                           {
                              "name":"link2"
                           }
                        ]
                     }
                  ]
               }
            ]
         }
      }
   }
}

JQGrid Definition

$("#myjqgrid").jqGrid({
   url: "jqgrid.json",
   datatype: "json",
   contentType: "application/x-javascript; charset=utf-8",
   colNames:['linkimg'],
   colModel:[
      {name:'linkimg',index:'linkimg', width:100, align:"center", resizable:false}
   ],
   jsonReader: {
       root: "mypage.outerwrapper.innerwrapper.rows",
       repeatitems: false
   }
})

loadComplete

loadComplete: function(data){
    var x, y, cellProp, item;
    for (x = 0; x < data.mypage.outerwrapper.innerwrapper.rows.length; x++) {
        item = data.mypage.outerwrapper.innerwrapper.rows[x];
        var cellCount = data.mypage.outerwrapper.innerwrapper.rows[x].cells.length;
        for (y = 0; y < cellCount; y += 1) {
            cellProp = data.mypage.outerwrapper.innerwrapper.rows[x].cells[y];
            if (cellProp.label === "linkimg") {
                var linkimgItem = data.mypage.outerwrapper.innerwrapper.rows[x].cells[y].links;
                var linkimgCount = data.mypage.outerwrapper.innerwrapper.rows[x].cells[y].links.length;         
                var g;
                if (linkimgCount === 2) {
                    for (g = 0; g < linkimgCount; g += 1) {
                         $("td[aria-describedby='myjqgrid_" + cellProp.label + "']").append("<span style='padding-right:5px'><a href='#'>"+data.page.outerwrapper.innerwrapper.rows[x].cells[y].links[g].name+"</a></span>");                               
                    }
                }else{
                      $("td[aria-describedby='myjqgrid_" + cellProp.label + "']").append("<img src='images/icon.gif' width='10' height='10'>"); 
                }           
            }
        }
    }
}

What I’m trying to do

Each row has only 1 cell – linkimg. I loop through each row and then each cell, then count the number of items in the links array.

If label = linkimg and the number of items in links array = 2, I want the value of the column to be hyperlinks

<span><a>link1</a><span><span><a>link2</a></span>

If label = linkimg and the number of items in links array > 2, I want the value of the column to be an image

<img src='images/icon.gif' width='10' height='10'>

Problem that I’m having

With the above code, the column in each row gets the following output:

<img src='images/icon.gif' width='10' height='10'><span><a>link1</a><span><span><a>link2</a></span>

The output should be

First Row – <img src='images/icon.gif' width='10' height='10'>

Second Row – <span><a>link1</a> <span><span><a>link2</a></span>

Third Row – <span><a>link1</a> <span><span><a>link2</a></span>

  • 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-05-27T15:15:12+00:00Added an answer on May 27, 2026 at 3:15 pm

    Look at the demo. It should solve your problem.

    The idea of the solution is

    1. To save the cells property of the input data in the object cellsById so that one can get the cells by the rowid with respect of cellsById[rowid].
    2. To use custom formatter to format the contain of the ‘linkimg’ column based on the cells property. We will get cells from the rawObject parameter of the custom formatter (as rawObject.cells) or we will get the same data from cellsById. We get the rowid of the current formatted row from the options parameter (as options.rowId).

    The most important code fragments are

    formatter: function (val, options, rawObject) {
        var l, i, cellProp, linkimgItem, linkimgCount, g,
            cells = $.isEmptyObject(cellsById) ?
                    rawObject.cells :
                    cellsById[options.rowId];
        if (typeof cells !== "undefined" && cells.length > 0) {
            for (i = 0, l = cells.length; i < l; i++) {
                cellProp = cells[i];
                if (cellProp.label === "linkimg") {
                    linkimgItem = cellProp.links;
                    linkimgCount = linkimgItem.length;
                    if (linkimgCount === 2) {
                        val = '';
                        for (g = 0; g < linkimgCount; g += 1) {
                            val += "<span style='padding-right:5px'><a href='#'>" +
                                    linkimgItem[g].name + "</a></span>";
                        }
                    } else {
                        val = "<img src='images/icon.gif' width='10' height='10'>";
                    }
                }
            }
        }
        return val;
    }}
    

    and

    loadComplete: function (data) {
        var rows, i, l, item;
        if (typeof data.mypage !== "undefined") {
            rows = data.mypage.outerwrapper.innerwrapper.rows;
            for (i = 0, l = rows.length; i < l; i++) {
                item = rows[i];
                cellsById[item.id] = item.cells;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following JSON structure JSON { page:1, total:3, records:15, mypage:{ outerwrapper:{ innerwrapper:{
I am loading JSON data to my page and using appendTo() but I am
My JSON Data {menu: { id: file, value: File, popup: { menuitem: [ {value:
I have specified userdata in JSON response. Depending on the value of the title
I have passed some JSON to my page via a webservice. I used JSON.NET
When someone first goes to my page, I create it from JSON using a
I have some links that are placed in my page dynamically via JSON and
i call my asp.net page method like below code $.ajax({ type: POST, url: MyPage.aspx/GetItems,
I need to convert the output of an .aspx page into a JSON object
Okay so I got my page up and running and grabbing JSON and outputting

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.