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

The Archive Base Latest Questions

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

I am trying to add a function named rows to the jqGrid jQuery plugin,

  • 0

I am trying to add a function named rows to the jqGrid jQuery plugin, but I can’t determine the syntax. Here are my non-working versions.

(function($) {
 $.fn.jgrid.rows = function(data) {
   // do something
 };
});

(function($) {
 $.fn.rows = function(data) {
   // do something
 };
});

 $.jqgrid.fn.rows = function(data) {
   // do something
 };

 $.fn.rows = function(data) {
   // do something
 };

What would be the proper syntax?

Thanks!

  • 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-23T07:19:19+00:00Added an answer on May 23, 2026 at 7:19 am

    It seems the correct answer on your question depends a little from what should do the method rows which you want to implement. I try to guess a little and gives the implementation which correspond to my understanding of your question.

    First of all jqGrid is jQuery plugin and if you write for example

    $(myselector).jqGrid('setSelection',rowid);
    

    it can be that $(myselector) selects more as one DOM element. For example

    $('table').jqGrid('setSelection',rowid);
    

    will try call jqGrid method ‘setSelection’ on all <table> elements on the page. So this element in the array of DOM elements (it should be <table> DOM elements) and not only one element.

    Another general remark. There are jQuery methods which can be chained like

    $("#list").jqGrid('setGridParam',{datatype:'json'}).trigger('reloadGrid');
    

    In the case the ‘setGridParam’ do something and return this to support chaining. Other methods don’t support chaining and return what the method need to return. For example getDataIDs returns the array of ids and one can’t chain getDataIDs with another jQuery methods.

    Now I return back to your question. I would better name the new method getRowsById. The method will return array with DOM elements which represent <tr> (table row). The method will have rowid as the parameter. Then one can extend jqGrid with the new method in the way:

    $.jgrid.extend({
        getRowsById: function (rowid){
            var totalRows = [];
            // enum all elements of the jQuery object
            this.each(function(){
                if (!this.grid) { return; }
                    // this is the DOM of the table
                    // we
                    var tr = this.rows.namedItem(rowid);
                    if (tr !== null) { // or if (tr !== null)
                        totalRows.push(tr);
                    }
            });
            return totalRows;
        }
    });
    

    First of all I use in the example the method $.jgrid.extend defined here. It does mostly $.extend($.fn.jqGrid,methods);. Then, because the method which we implement can’t be chained, we define totalRows variable which will be returned later as the result of the method. Now we have to enumerate all objects from the this (like elements of $(myselector) or $('table') in the examples above). We do this with respect of this.each(function(){/*do here*/}); construct. Then inside of the loop we do following

    if (!this.grid) { return; }
    

    With the statement we test whether the current DOM element has grid property. It is not a standard property of the table element, but jqGrid extend the DOM elements of the table with the property. With the test we could skip for example other table elements where the jqGrid are not applied (which are not a jqGrid). Then I use the fact that this must be DOM of the table element which has rows property (see here, and here) and I use its namedItem method. The native implemented method works better as $(“#”+rowid), but do the same. After all we return the array totalRows. It will have no element if the row with the row id not in the grid and 1 if it is exist. If the current jQuery selector select more as one grid and we had an error and included in both grids rows with the same id the returned array will has length greater as 1. So we can use it so

    var grid = $("#list");
    var tr = grid.jqGrid('getRowById','1111');
    alert(tr.length);
    

    At the end I want to mention that the method $.jgrid.extend can be helpful not only if you want to introduce new jqGrid method. Sometime there are already some jqGrid method, but it does not exactly what you need. So you want that the modified method do something at the beginning or something at the end of the original jqGrid method. In the case we can do the following

    var oldEditCell = $.fn.jqGrid.editCell;
    $.jgrid.extend({
        editCell: function (iRow,iCol, ed){
            var ret;
            // do someting before
            ret = oldEditCell.call (this, iRow, iCol, ed);
            // do something after
            return ret; // return original or modified results
        }
    });
    

    In the example we overwrite the original editCell method with will be called by jqGrid itself and do something before of something after the call.

    • 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
I'm trying to add the JavaScript function setTimeout() to my jQuery expression. Without the
At www.euroworker.no/order I have been trying to add a tooltip function but it seems
Here am trying to add a html rows by clicking on the add button
I'm trying to add a new method to jQuery validation plugin with the codes
I'm trying to make Jquery delete function, here is the code, that I wrote
I'm trying to add a function that will be accessible throughout all parts of
I am trying to use the $addHandler function to add a handler to a
I'm trying to extend jWysiwyg with an function to add a map from Google
I am trying to set the compilation-error-regexp-alist in a function that I add as

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.