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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:39:45+00:00 2026-05-20T09:39:45+00:00

This is almost continuation of a previous question. Problem showing jqgrid with dynamic column

  • 0

This is almost continuation of a previous question. Problem showing jqgrid with dynamic column binding

I am trying to put a Custom Formatter for the columns like below. But nothing happens. Please help.

JSP:

   <html xmlns="http://www.w3.org/1999/xhtml">
  <head>
  <script type="text/javascript"> 
  $(document).ready(function() {
  $.ajax( {
    type : "GET",
    url : "interFinalTbaAction",
    data : "",
    dataType : "json",
    success : function(result) {
        var colD = result.couponStripList, colM = result.colModelList;
        jQuery("#InterFinalTBAGrid").jqGrid( {
            data : colD.rootVar,
            datatype : 'local',
            gridview : true,
            colModel : colM,
            loadComplete : function(data) {
            },
            loadError : function(xhr, status, error) {
                alert('grid loading error');
            }
        });
    },
    error : function(x, e) {
        alert(x.readyState + " " + x.status + " " + e.msg);
    }
});
  });
 </script>
 </head>
 <body>
 <table id="InterFinalTBAGrid">
<tr>
    <td />
</tr>
 </table>
 </body>
 </html>  

The JSON result from action:

 {
"colModelList": [
    {
        "formatter": "CouponFormatter",
        "index": 0,
        "jsonmap": null,
        "key": false,
        "label": "Coupon",
        "name": "coupon",
        "resizable": true,
        "search": true,
        "sortable": false,
        "title": true,
        "width": 100
    },
    {
        "formatter": "InterFinalPriceFormatter",
        "index": 1,
        "jsonmap": null,
        "key": false,
        "label": "03-10-11",
        "name": "prceCM",
        "resizable": true,
        "search": true,
        "sortable": false,
        "title": true,
        "width": 150
    },
    {
        "formatter": "InterFinalPriceFormatter",
        "index": 2,
        "jsonmap": null,
        "key": false,
        "label": "04-13-11",
        "name": "prceCMPlusOne",
        "resizable": true,
        "search": true,
        "sortable": false,
        "title": true,
        "width": 150
    },
    {
        "formatter": "InterFinalPriceFormatter",
        "index": 3,
        "jsonmap": null,
        "key": false,
        "label": "05-12-11",
        "name": "prceCMPlusTwo",
        "resizable": true,
        "search": true,
        "sortable": false,
        "title": true,
        "width": 150
    },
    {
        "formatter": "InterFinalPriceFormatter",
        "index": 4,
        "jsonmap": null,
        "key": false,
        "label": "06-13-11",
        "name": "prceCMPlusThree",
        "resizable": true,
        "search": true,
        "sortable": false,
        "title": true,
        "width": 150
      }
   ],
   "couponStripList": {
    "rootVar": [
        {
            "coupon": 5.0,
            "prceCM": "103.734375,103.734375",
            "prceCMPlusOne": "103.359375,99.03",
            "prceCMPlusThree": "102.671875,102.671875",
            "prceCMPlusTwo": "103.015625,103.015625"
        },
        {
            "coupon": 5.5,
            "prceCM": "105.984375,105.984375",
            "prceCMPlusOne": "105.671875,99.2",
            "prceCMPlusThree": "105.046875,105.046875",
            "prceCMPlusTwo": "105.359375,105.359375"
        }

    ]
   },
   "deliveredDataTimestamp": "03-02-11 11:52:57",
   "requestedTimestamp": null
   }

The Javascript functions for formatters:

  function CouponFormatter(cellValue, opts, rowObject) {
return cellValue + "Testing coupon formatter";
   }

function InterFinalPriceFormatter(cellValue, opts, rowObject) {
return cellValue + "Testing price formatter";
}
  • 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-20T09:39:45+00:00Added an answer on May 20, 2026 at 9:39 am

    If you use

    "formatter": "InterFinalPriceFormatter"
    

    you don’t set the value of “formatter” property to the function.

    One way to fix the problem is to loop through result.colModelList and verify that one use “formatter” property with some string value for which you has implementation as the function in the JavaScript. Then you can overwrite the property with the value of the corresponding formatter function.

    Another way will be use inline functions in the formatter:

    "formatter": "function (cellValue, opts, rowObject) { return cellValue + \"Testing price formatter\"; }"
    

    In the way you will be not has clear separation of the code and the grid parameters, but you receive some encapsulation of the formatter inside the grid.

    UPDATED: I hope that the next code fragment (untested) could make clear what I mean under the first implementation way

    var functionsMapping = {
        // here we define the implementations of the custom formatter which we use
        "CouponFormatter": function (cellValue, opts, rowObject) {
            return cellValue + "Testing coupon formatter";
        },
        "InterFinalPriceFormatter": function (cellValue, opts, rowObject) {
            return cellValue + "Testing price formatter";
        }
    };
    $.ajax({
        type: "POST",
        url: "interFinalTbaAction.action",
        data: "",
        dataType: "json",
        success: function(result) {
            var i, cm, colD = result.couponStripList,
                colN = result.columnNames,
                colM = result.colModelList;
            for (i=0;i<colM.length,i++) {
                cm = colM[i];
                if (cm.hasOwnProperty("formatter") &&
                    functionsMapping.hasOwnProperty(cm.formatter)) {
                    // fix colM[i].formatter from string to the function
                    cm.formatter = functionsMapping[cm.formatter];
                }
            }
            jQuery("#dataGrid").jqGrid({/* all parameters from your code */});
        },         
        error: function(jqXHR, textStatus, errorThrown){
            alert("Error Occured!" + " | " + jqXHR.responseText + " | " +
                  textStatus + " | " + errorThrown);
        }
    });
    

    UPDATED 2: It would be better to register the custom formatters and unformatters as standard formatters like it’s described in the old answer or in answer one. After that one can really use the syntax like "formatter": "InterFinalPriceFormatter" and the custom defined functions $.fn.fmatter.InterFinalPriceFormatter and $.fn.fmatter.InterFinalPriceFormatter.unformat will be automatically called by jqGrid.

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

Sidebar

Related Questions

I'm almost certain I know the answer to this question, but I'm hoping there's
When I asked this question I got almost always a definite yes you should
Note: Originally this question was asked for PostgreSQL, however, the answer applies to almost
This is almost certainly a very novice question, but being as I am a
This is almost identical problem which I faced a few days ago . I
Almost 5 years ago Joel Spolsky wrote this article, The Absolute Minimum Every Software
This is something that comes up so often I almost stopped thinking about it
I know almost nothing about linq. I'm doing this: var apps = from app
I'm almost finished with the book Head First Java. The reason I'm studying this
Duplicate post, see: When do you use the "this" keyword? On almost every project

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.