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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:03:22+00:00 2026-05-14T20:03:22+00:00

I am using a custom formatter for my jqGrid columnModel and I can’t get

  • 0

I am using a custom formatter for my jqGrid columnModel and I can’t get sorting to work with formatter functions. If I remove formatter column sorts normally.

jQuery("#listAgentOptions").jqGrid({
    height: 240,
    datatype: "local",
    colNames: [' ', 'First Name', 'Last Name', 'Role'],
    colModel: [
    { name: 'status', index: 'status', width: 18, sorttype: 'text', align: 'center', formatter: function(cellvalue, options, rowObject) {
        return cellvalue == 1 ? "<img src='images/agent_green_s.png' alt='Ready' title='Ready' />" :
        cellvalue == 3 ? "<img src='images/agent_red_s.png' alt='Busy' title='Busy' />" :
        "<img src='images/agent_orange_s.png' alt='Pending Ready' title='Pending Ready' />";
    },
        unformat:
    function(cellvalue, options, rowObject) { return Math.floor(Math.random() + 0.1).toString(); }
    },
    { name: 'firstName', index: 'firstName', width: 92 },
    { name: 'lastName', index: 'lastName', width: 142 },
    { name: 'role', index: 'role', sorttype: 'int', width: 36, align: 'center', formatter: function(cellvalue, options, rowObject) {
        return cellvalue == true ? "<img src='images/user_gray.png' alt='Supervisor' title='Supervisor' />" : "<img src='images/user.png' alt='Agent' title='Agent' />";
    }, unformat:
    function(cellvalue, options, rowObject) { return cellvalue; }
    }
    ],
    sortname: 'lastName'
});

Rows are added like this:

jQuery("#listAgentOptions").jqGrid('clearGridData');
$.each(result, function(i, item) {
    if (item.ContactType == 1) {
        jQuery("#listAgentOptions").jqGrid('addRowData', i+1, { firstName: item.ContactName.split(" ")[0], lastName: item.ContactName.split(" ")[1],
        role: item.IsSupervisor,
        status: item.Status == "Ready" ? 1 : item.Status == "Busy" ? 3 : 2
        });
    }
});

How do I get sorting to work properly?

Update. I have just downloaded the latest version of jqGrid – same issue.

I have also tried using unformat: function(cellvalue, options, rowObject) { } but cellvalue is empty there :-E When I use return Math.floor(Math.random() + 0.1).toString(); it does sort things randomly (each time I click), but return cellvalue; just returns an empty string.

  • 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-14T20:03:22+00:00Added an answer on May 14, 2026 at 8:03 pm

    OK, I have figured out what’s going on.

    First of all you have to use unformat to pass the initial value back to jqGrid sort function.

    jqGrid is passing $(row).text() to unformat function, which for cells with just an html tag returns an empty string, and there is no option to change it. However, what you can do is use the third parameter of unformat function, which in my case is rowObject. You can then retrieve the actual cell value by using $(rowObject).html() and parse it back to the value. Sorting will now work.

    Another thing to remember is that if you are using sorrtype: 'int' you will have to return integer as a string, like return '1';.

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

Sidebar

Related Questions

For one of the columns in my jqGrid, I'm providing a custom formatter function.
I am using log.properties to configure logging for a Java app. Each class gets
Have you ever seen a good reason to create a custom binary rest protocol
To help simplify debugging of some custom Objective-C objects in the Xcode debugger window,
I'm using a NSDateFormatter to parse a RFC 822 date on the iPhone. However,
I recently wrote a custom Debugger Visualizer for Visual Studio 2008 for one of
I have been using BinaryFormatter to serialise data to disk but it doesn't seem
I have a source object that looks like this: private class SourceObject { public
I am new to creating plug-ins, and there's much that I don't understand. One

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.