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

  • Home
  • SEARCH
  • 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 3430286
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:11:11+00:00 2026-05-18T07:11:11+00:00

I cannot add a row to the top of a jqGrid table using the

  • 0

I cannot add a row to the top of a jqGrid table using the line:

jQuery("#myTable").jqGrid('addRowData', 0, myData, "first");

It just adds to the bottom of the list as usual

Has anyone tried this and works for them?

In my table, previously added rows have index that goes from 0 to N

I am using jqGrid v3.8.1 and jQuery 1.4.3

<html>

<head>
    <link rel="stylesheet" type="text/css" media="screen" href="css/jquery-ui-1.8.5.custom.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />

    <script src="js/jquery-1.4.3.js" type="text/javascript"></script>
    <script src="js/i18n/grid.locale-en.js" type="text/javascript"></script>
    <script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
    <script src="js/jquery-ui-1.8.5.custom.min.js" type="text/javascript"></script>
</head>

<script type="text/javascript">
    $(document).ready(function () {


        jQuery("#myTable").jqGrid({
            datatype: "local",
            colNames: ['Data ID', 'Device'],
            colModel: [{
                    name: 'DATA_ID',
                    index: 'DATA_ID',
                    sorttype: "int",
                    width: 22,
                    align: "center",
                    sortable: false
                },
                {
                    name: 'DATA_DN',
                    index: 'DATA_DN',
                    width: 60,
                    align: "center",
                    sortable: false
                },
            ],
            width: "1216",

        });

        var myData = [{
            "DATA_ID": "9",
            "DATA_DN": "sony"
        }, {
            "DATA_ID": "10",
            "DATA_DN": "panasonic"
        }];
        var newData = [{
            "DATA_ID": "0",
            "DATA_DN": "national"
        }, {
            "DATA_ID": "1",
            "DATA_DN": "samsung"
        }];

        for (var i = 0; i < myData.length; i++) {
            jQuery("#myTable").jqGrid('addRowData', i, myData[i]);
        }

        jQuery("#myTable").addRowData(0, newData, "first");

        //jQuery("#myTable").trigger("reloadGrid");

    });
</script>
</head>

<body>
    <table id="myTable"></table>
    <div id="myTable_pager"></div>
</body>

</html>
  • 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-18T07:11:12+00:00Added an answer on May 18, 2026 at 7:11 am

    It’s a pity that you don’t post the full JavaScript code which you use. So I can only guess what happens.

    For example, if you define myData as an array ([...]) instead of an object ({...}) the position parameter will be overwritten with the value “last”.

    jqGrid is an open source project and you can examine what exactly do the addRowData function here. You can exactly see in which situation the position parameter “last” will be used.

    If you append your question with the code which can be used to reproduce the problem which you describes other could verify the code and either find a bug in the jqGrid or find a bug in your code. In both situation you have good chance to will be a winner.

    UPDATED The code which you posted have some small problems.

    First you should remove comma before ‘]’ in the colModel definition.
    Second the newData is an array so the last parameter will be replaced from “first” to “last”.
    Some other small but important problems are: you have to use <!DOCTYPE html ...> at the beginning of your HTML code, place the JavaScript code inside of //<![CDATA[ … //]]> and insert <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> in the HTML header.

    The fixed code will be following

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Demonstration how programatically select grid row which are not on the first page</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
        <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/themes/redmond/jquery-ui.css" />
        <link rel="stylesheet" type="text/css" href="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-3.8.1/css/ui.jqgrid.css" />
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
        <script type="text/javascript" src="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-3.8.1/js/i18n/grid.locale-en.js"></script>
        <script type="text/javascript" src="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-3.8.1/js/jquery.jqGrid.min.js"></script>
        <script type="text/javascript">
        //<![CDATA[
            jQuery(document).ready(function () {
                var grid = jQuery("#myTable");
                grid.jqGrid({
                    datatype: "local",
                    colNames:['Data ID','Device'],
                    colModel:[
                        {name:'DATA_ID',index:'DATA_ID', sorttype:"int", width:22, align:"center", sortable:false},
                        {name:'DATA_DN',index:'DATA_DN', width:60, align:"center", sortable:false},
                    ],
                    width: "1216"
                  });
    
                var myData = [{"DATA_ID":"9", "DATA_DN": "sony"}, {"DATA_ID":"10", "DATA_DN": "panasonic"}];
                var newData = [{"DATA_ID":"0", "DATA_DN": "national"}, {"DATA_ID":"1", "DATA_DN": "samsung"}];
    
                for(var i=0;i<myData.length;i++) {
                    grid.jqGrid('addRowData', i, myData[i]);
                }
    
                for (i=0;i<newData.length;i++) {
                    grid.jqGrid('addRowData', myData.length+i, newData[newData.length-i-1], "first");
                }
                //grid.trigger("reloadGrid");
            });
        //]]>
        </script>
    </head>
    <body>
        <table id="myTable"><tr><td/></tr></table>
    </body>
    </html>
    

    see also it live here. How you can verify with W3 Validator the last version of HTML code is correct.

    Nevertheless the usage of an additional hidden column which will be used for the sorting is the recommended way.

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

Sidebar

Related Questions

I'm trying to use jQuery to add dynamic Add/Remove row function, but I meet
Update: looks like this is indeed a WiX limitation - Cannot add 64bit com+
I cannot seem to access the context object using a loop context is set:
I'm trying to add a foreign key to an existing table, and was having
I have a multi-row insert that looks something like: insert into table VALUES (1,
I get error 1452 when trying to do this: ALTER TABLE test.potovanja ADD CONSTRAINT
Just a quick question, on which I cannot find a good reference, especially with
I cannot figure out how to change the title bar icon (the icon in
I cannot understand the Oracle documentation. :-( Does anybody know how to fetch multiple
I cannot correctly position the div form in my layout. By looking at my

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.