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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:32:03+00:00 2026-05-23T13:32:03+00:00

I have a function on my server code that returns a list of ElementRow

  • 0

I have a function on my server code that returns a list of ElementRow objects:

public class ElementRow {
    public string AreaName { get; set; }
    public YearData CurrentYear { get; set; }
    public YearData PreviousYear { get; set; }
}

public class YearData {
    public int Value1 { get; set; }
    public int Value2 { get; set; }
}

These classes generates a json like this one:

{"d":
    {
        "Total":2,
    "Page":1,
    "Records":30,
    "Rows":[
        {"AreaID":0,"CurrentYear":{"Value1":1,"Value2":2},"PreviousYear":{"Value1":1,"Value2":2}},
        {"AreaID":1,"CurrentYear":{"Value1":5,"Value2":4},"PreviousYear":{"Value1":1,"Value2":2}},
        {"AreaID":2,"CurrentYear":{"Value1":2,"Value2":1},"PreviousYear":{"Value1":1,"Value2":2}},
        {"AreaID":3,"CurrentYear":{"Value1":1,"Value2":3},"PreviousYear":{"Value1":1,"Value2":2}}
    ],
    "UserData":null
    }
}

I have defined the colModel to support this data structure and would like to create a custom formatter function to format object of type YearData in one column. My colModel is as follow:

$("#dashboard").jqGrid({
    url: wsBaseUrl + 'MyWebService.asmx/MyMethod',
    colNames: ['Area Name','Current Year', 'Previous Year'],
    colModel: [
        { name: 'AreaName', index: 'AreaName', width: 120, template: colTextTemplate },
        { name: 'CurrentYear', index: 'CurrentYear', width: 100, align: 'center', sortable: false, formatter: YearDataFormatter },
        { name: 'PreviousYear', index: 'PreviousYear', width: 100, align: 'center', sortable: false, formatter: YearDataFormatter }
    ],
    jsonReader: {
        id: "AreaID"
    },
    pager: $('#dashboard_pager'),
    sortname: 'AreaName',
    sortorder: "asc",
    height: '250',
    rownumbers: false,
    gridview: false,
    subGrid: true,

    //subgrid definition omitted
});

and then defined the YearDataFormatter function as follow:

function YearDataFormatter(cellvalue, options, rowObject) {
    var table = "<table><tr>";
    table += "<td>" + cellvalue.Value1 + "</td>";
    table += "<td>" + cellvalue.Value2 + "</td>";
    table += "</tr></table>";
    return table;
}; 

Anyway when I try to execute this function the problem is that inside the YearDataFormatter function the value of cellvalue parameter is undefined while, looking at it with the debugger, there is a valid value inside the rowObject parameter.

How can I access correctly the value of that cell?

Also, is there any chance to modify the header for a particular column? I would like to create a two-line header but if I add markup inside the colNames option the header height does not change accordingly.

Thanks for your support!

  • 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-23T13:32:04+00:00Added an answer on May 23, 2026 at 1:32 pm

    You don’t posted the JSON or XML data which are used to fill the grid and the definition of jqGrid. The local data or in case of the usage of loadone:true the internal data will be saved and all works in another way. So the custom formatter should be used depend on the settings.

    Because I have not enough information I try to guess. I suppose that you should use

    function YearDataFormatter(cellvalue, options, rowObject) {
        var table = "<table><tr>",
            cellData = rowObject.CurrentYear; // or like rowObject[2]
        table += "<td>" + cellData.Value1 + "</td>";
        table += "<td>" + cellData.Value2 + "</td>";
        table += "</tr></table>";
        return table;
    };
    

    The best would be to change the format of data which the server use for the date and use ISO 8601 date format. If you use .NET you can use “o” or “O” formatter of the DateTime. In the case you can use formatter:'date' or formatter:'date', formatoptions:{srcformat:'ISO8601Long'}.

    UPDATED: I am sure that you use much more default settings in the jqGrid definition. Without additional settings you can’t read the JSON data. After small modification the demo read the data and I don’t see any problem with the custom formatter which you use: see here:

    enter image description here

    You can compare the demo with youth to see the differences.

    About your second question (multiline data in the grid header) I recommend you to look at here:

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

Sidebar

Related Questions

I have a function that gets x(a value) and xs(a list) and removes all
I have a function that looks like this class NSNode { function insertAfter(NSNode $node)
We have a Single Statement FUNCTION in SQL Server 2005 which uses CONTAINSTABLE(). All
I have some content from server using $.ajax() function. I try to replace some
I have a function that gives me the following warning: [DCC Warning] filename.pas(6939): W1035
I have a function where I need to do something to a string. I
I have a function that takes, amongst others, a parameter declared as int privateCount
I have a function in a native DLL defined as follows: #include <string> void
I have a function, parseQuery, that parses a SQL query into an abstract representation
I have this part of code in my application. card.getcard(command, function(toproceed,resultscard) { console.log('entry other

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.