I have json like below
[
{
"UserName": "John Robertson",
"OperatorUserId": 1177,
"PartCategoryID": 0,
"PartCategoryName": null,
"UnitCount": 22,
"CategoryWiseCount": 13,
"TotalUsers": 0,
"TotalCategories": 0,
"MainArrayCount": null,
"NewMainArrayCount": null,
"ListCategorywiseCount": [6, 1, 2, 0, 0, 0, 13, 0, 0],
"ListCategories": ["Base Unit", "Hard Drive", "Laptop", "Laptop AC Adapter", "Motherboard", "Optical Drive", "Processor (CPU)", "Server", "TFT"],
"ListUsers": ["John Robertson", "user1", "Margaret Graham", "Stuart White", "Bob van Schie", "Caird Hay", "bsoni", "tsname"]
}, {
"UserName": "user1",
"OperatorUserId": 39,
"PartCategoryID": 0,
"PartCategoryName": null,
"UnitCount": 13,
"CategoryWiseCount": 1,
"TotalUsers": 0,
"TotalCategories": 0,
"MainArrayCount": null,
"NewMainArrayCount": null,
"ListCategorywiseCount": [1, 0, 3, 1, 1, 0, 0, 6, 1],
"ListCategories": ["Base Unit", "Hard Drive", "Laptop", "Laptop AC Adapter", "Motherboard", "Optical Drive", "Processor (CPU)", "Server", "TFT"],
"ListUsers": ["John Robertson", "user1", "Margaret Graham", "Stuart White", "Bob van Schie", "Caird Hay", "bsoni", "tsname"]
}, {
"UserName": "Margaret Graham",
"OperatorUserId": 1169,
"PartCategoryID": 0,
"PartCategoryName": null,
"UnitCount": 2,
"CategoryWiseCount": 2,
"TotalUsers": 0,
"TotalCategories": 0,
"MainArrayCount": null,
"NewMainArrayCount": null,
"ListCategorywiseCount": [2, 0, 0, 0, 0, 0, 0, 0, 0],
"ListCategories": ["Base Unit", "Hard Drive", "Laptop", "Laptop AC Adapter", "Motherboard", "Optical Drive", "Processor (CPU)", "Server", "TFT"],
"ListUsers": ["John Robertson", "user1", "Margaret Graham", "Stuart White", "Bob van Schie", "Caird Hay", "bsoni", "tsname"]
}, {
"UserName": "Stuart White",
"OperatorUserId": 961,
"PartCategoryID": 0,
"PartCategoryName": null,
"UnitCount": 1,
"CategoryWiseCount": 1,
"TotalUsers": 0,
"TotalCategories": 0,
"MainArrayCount": null,
"NewMainArrayCount": null,
"ListCategorywiseCount": [0, 1, 0, 0, 0, 0, 0, 0, 0],
"ListCategories": ["Base Unit", "Hard Drive", "Laptop", "Laptop AC Adapter", "Motherboard", "Optical Drive", "Processor (CPU)", "Server", "TFT"],
"ListUsers": ["John Robertson", "user1", "Margaret Graham", "Stuart White", "Bob van Schie", "Caird Hay", "bsoni", "tsname"]
}, {
"UserName": "Bob van Schie",
"OperatorUserId": 1007,
"PartCategoryID": 0,
"PartCategoryName": null,
"UnitCount": 1,
"CategoryWiseCount": 1,
"TotalUsers": 0,
"TotalCategories": 0,
"MainArrayCount": null,
"NewMainArrayCount": null,
"ListCategorywiseCount": [0, 1, 0, 0, 0, 0, 0, 0, 0],
"ListCategories": ["Base Unit", "Hard Drive", "Laptop", "Laptop AC Adapter", "Motherboard", "Optical Drive", "Processor (CPU)", "Server", "TFT"],
"ListUsers": ["John Robertson", "user1", "Margaret Graham", "Stuart White", "Bob van Schie", "Caird Hay", "bsoni", "tsname"]
}, {
"UserName": "Caird Hay",
"OperatorUserId": 1184,
"PartCategoryID": 0,
"PartCategoryName": null,
"UnitCount": 1,
"CategoryWiseCount": 1,
"TotalUsers": 0,
"TotalCategories": 0,
"MainArrayCount": null,
"NewMainArrayCount": null,
"ListCategorywiseCount": [0, 1, 0, 0, 0, 0, 0, 0, 0],
"ListCategories": ["Base Unit", "Hard Drive", "Laptop", "Laptop AC Adapter", "Motherboard", "Optical Drive", "Processor (CPU)", "Server", "TFT"],
"ListUsers": ["John Robertson", "user1", "Margaret Graham", "Stuart White", "Bob van Schie", "Caird Hay", "bsoni", "tsname"]
}, {
"UserName": "bsoni",
"OperatorUserId": 2575,
"PartCategoryID": 0,
"PartCategoryName": null,
"UnitCount": 3,
"CategoryWiseCount": 2,
"TotalUsers": 0,
"TotalCategories": 0,
"MainArrayCount": null,
"NewMainArrayCount": null,
"ListCategorywiseCount": [0, 0, 0, 0, 1, 0, 2, 0, 0],
"ListCategories": ["Base Unit", "Hard Drive", "Laptop", "Laptop AC Adapter", "Motherboard", "Optical Drive", "Processor (CPU)", "Server", "TFT"],
"ListUsers": ["John Robertson", "user1", "Margaret Graham", "Stuart White", "Bob van Schie", "Caird Hay", "bsoni", "tsname"]
}, {
"UserName": "tsname",
"OperatorUserId": 2576,
"PartCategoryID": 0,
"PartCategoryName": null,
"UnitCount": 1,
"CategoryWiseCount": 1,
"TotalUsers": 0,
"TotalCategories": 0,
"MainArrayCount": null,
"NewMainArrayCount": null,
"ListCategorywiseCount": [0, 0, 0, 0, 0, 1, 0, 0, 0],
"ListCategories": ["Base Unit", "Hard Drive", "Laptop", "Laptop AC Adapter", "Motherboard", "Optical Drive", "Processor (CPU)", "Server", "TFT"],
"ListUsers": ["John Robertson", "user1", "Margaret Graham", "Stuart White", "Bob van Schie", "Caird Hay", "bsoni", "tsname"]
}]
I want to look above data in grid using jquery template.
John Robertson User1 Margaret Graham .....
Base unit 6 1 ...
Hard Drive 1 0 ...
.....
Explanation
There are a few things that need to be clear before we start.
First:
I’m assuming that by “template” you mean a plugin, because the JQuery.template is still in it’s beta, and it’s not really recommended to use yet. Besides, it won’t really do you much.
You can learn how to build your own plugins by starting here, I am however going to give you a complete example of how this is done (further down).
Generally, when you want an element related to your plugin, it begins with
Otherwise, as a general function accessed through
$, it’s justSecond:
When sending JSON through AJAX you’d want to have an object tied to your JSON, not an array. JSON stands for JavaScript Object Notation, so even by looking at the name, it should tell you it’s got something to do with objects.
In other words, you need to send back an object using curly braces
{}.So, your JSON should look something like this
You can read more about what it is on wikipedia.
Third:
For clarification, to request JSON data on an AJAX call, you have to specify the
dataTypeas JSON. It is done like thisNote that I used the function
JSON.stringify, which serializes (puts all the variables into text) the variable. Great for debugging purposes! 🙂Alternatively, you can use the shorthand version, getJSON
Solution
Before I give you the code, here is a screenshot of what your result should look like.

Of course, I’m not saying you should do exactly as I did, in fact, I encourage you to do it differently. Practice makes perfect. Besides, that might not be the kind of layout you wanted.
As promised, here’s all the code to produce the above screenshot.
I’ll start with the JavaScript file and JSON output, as they are the most relevant.
Note that all files are within the same folder.
File: JavaScript “example.js”
File: Text document “example_json_output.txt”
File: HTML “example.html”
File: CSS “example.css”