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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:23:03+00:00 2026-06-15T20:23:03+00:00

I am newbie to jqGrid , and populating data from Servlet via Ajax call

  • 0

I am newbie to jqGrid, and populating data from Servlet via Ajax call and displaying in jqGrid. This works fine no problem. But, In my case column names are dynamic, as I am showing dates as column names.

So, I found below code when searching for Dynamic colModel for jqGRid.

But, This causes two Ajax call. Has anyone worked with dynamic column headers ?

<script type="text/javascript"> 

    var grid = $("#rowsList");
    var url = '/getRowList?Id=9371&fromDate=2011-12-06&toDate=2012-12-06';
    jQuery().ready(function (){ 
        $.ajax({
            url: url,
            dataType: 'json',
            success: function(response) {
                prepareGrid(response);
            },
            error: function(request, textStatus, errorThrown) {
                alert(textStatus + " : " + request.responseText);
            }
        });
    });

    function prepareGrid(response){
        if (response) {
            if (!response.Error) {
                var colData = getColumnsData(response.columnData);
                colData = eval('{' + colData + '}');

                grid.jqGrid({ // This makes second server call
                    url: url,
                    datatype: 'json',
                    mtype: 'POST',
                    colModel: colData,
                    colNames: response.columnData,
                    height : 'auto',
                    pager: '#pager',
                    viewrecords: true,
                    loadtext: 'Loading',
                    sortorder: "asc",
                    gridview: true,
                    altRows: true,
                    cellEdit: false,
                    caption: 'Data List' 
                });
            }
        }
    }

    /**
     * Creates column data for jqgrid
     */
    function getColumnsData(Data) {
        // return column data array in jqGrid compatible format
        // This works fine
    }

</script> 

My other choice to return only column names in the first call and set colModels but It would be better if it can be done in single server call.

  • 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-06-15T20:23:04+00:00Added an answer on June 15, 2026 at 8:23 pm

    I want to warn you with reducing of the number of Ajax calls. If you are newbie in jqGrid it’s important to understand some common thing in the usage of jqGrid:

    • jqGrid need be initialized once during call of grid.jqGrid({...});.
    • the url will be used multiple times by jqGrid.

    The grid has some common user interface elements in pager (see the answer)

    enter image description here

    enter image description here

    which can be used by user to interact with jqGrid. So if the user click on the “Next Page” button, Change the number of displayed rows or change the sorting column (or the direction of sorting) new request to the server, to url will be send. It is very practical to use other elements of user interface like searching tool:

    enter image description here

    which also produce new request to url with modified parameters. After receiving the server response only the grid body will be replaced. The other parts of the grid will stay unchanged. You can use GridUnload method to recreate the whole grid (see here examples)

    So if you would transfer column definition every time together with the data of the grid you will send unneeded data, which can reduce the performance instead of improving which you want.

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

Sidebar

Related Questions

Newbie ajax question from this example : How is xmlhttp.responseText assigned before xmlhttp.open() and
I'm a jQuery/jqGrid newbie... I've got my jqGrid selecting and displaying my data correctly.
Newbie question here but for some reason I cant figure this out. I have
I am a newbie to jqGrid, I am using jqGrid-4.4.0 to display values from
Newbie :( Tweaking my way through tutorials but 36 hours can't figure this one
Newbie to .NET data apps here, coming from a Visual Foxpro background. I'm planning
Newbie to this forum... I was working on something lately and encountered a problem.
newbie for clearcase. Since clearcase's config is rather different from other concept in git,
Newbie question. I have Django models that look like this: class Video(models.Model): uploaded_by =
Newbie question... I am using silverlight to POST data to my GAE application class

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.