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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:57:01+00:00 2026-06-15T23:57:01+00:00

I have a jqGrid Treegrid defined as below: $(‘#MyGrid’).jqGrid({ colNames: [‘Id’,’Nome’,’Nivel’,’Combo’,”], colModel: [ {

  • 0

I have a jqGrid Treegrid defined as below:

$('#MyGrid').jqGrid({
    colNames: ['Id','Nome','Nivel','Combo',''],
    colModel: [
        { hidden: true, name: 'Id' },
        { editable: true, name: 'Nome' },
        { hidden: true, name: 'Nivel' },
        { name: 'Combo', editable: true, edittype: 'select',
            editoptions: {
                buildSelect: createSelectList ,
                dataUrl: '/Home/GetCombo' // <-- to this controller, I want
                    // to send the id of the row edited to load custom items
                    // in select object
            }}, 
        { formatter: 'actions', formatoptions: { keys: true },
            resizable: false, search: false, sortable: false,
            width: 60, viewable: false, name: 'actions' }
    ],
    cellEdit: true,
    url: '...',
    datatype: 'json',
    editurl: '...',
    jsonReader: {
        repeatitems: false,
        id: 'Id',
        subgrid: { repeatitems: false }
    }, 
    mtype: 'POST',
    gridComplete: function() { myOnGridComplete(); },
    ajaxSelectOptions: {
        data: {
            tempid: function () {
                // !!! the next line always returns null
                return $('#MyGrid').jqGrid('getGridParam', 'selrow');
            }
        }
    }, 
    prmNames: { npage: 'npage' }, 
    rowNum: -1,
    ExpandColClick: true,
    ExpandColumn: 'Nome',
    treeGrid: true,
    treeGridModel: 'adjacency',
    width: 700,
    height: '100%'
});

My goal is to send the current row ID to the server, but when I use $(‘#MyGrid’).jqGrid(‘getGridParam’, ‘selrow’) I always get a null value.

I already read this posts but none of them solve my problem:

  • having trouble with jqgrid dataUrl function code segment

  • jqGrid setSelect function with parametrized query

  • jqGrid, how to populate select list from query

Any sugestions?

tks in advance!

Update 1:

The TreeGrid bind is ok. The real problem is when I click the Edit Button in the leaf node. In this event, I want to send additional data to the server.

I tried to accomplish this using the ajaxSelectOptions, but this command always returns null: $('#MyGrid').jqGrid('getGridParam', 'selrow')

Workaround

This is a workaround that I did before Oleg’s help:

Step 1: Create a hidden field in the HTML

Step 2: In my myOnGridComplete function, I set a click event to the edit button:

function onGridAjusteDTOComplete()
{
    $('#MyGrid').find('span.ui-icon-pencil').each(function() {
        $(this).click(function(){
            var rowID = $(this).parents('tr').attr('id');
            // !!! the next commented line not work in my case
            // $('#MyGrid').jqGrid('setSelection', therowid );
            $('#myHiddenField').val(rowID); // <-- this works
        });
    });
}

Step 3: Get the rowID from the hidden field in the ajaxSelectOptions:

ajaxSelectOptions: "{type: 'GET', contentType: 'application/json; charset=utf-8',dataType: 'json',cache: false, async:false, data: {id: function () { return $('#myHiddenField').val(); }}}"

Solution

See the solution provided by Oleg below. It’s just amazing. Thank you Oleg.

  • 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-15T23:57:01+00:00Added an answer on June 15, 2026 at 11:57 pm

    I am not sure that I understand your problem correctly. TreeGrid send automatically the id of parent node during loading of children nodes. See the documentation about nodeid, parentid, n_level parameters which will be send to the server. So I don’t understand why you could need to send the id of the currently selected row (selrow) additionally to the server.

    UPDATED: Now I understand the reason of the problem which you describe. It’s really interesting problem which could have other people.

    The real solution would be to change the code of jqGrid to support some callback function which could construct the data parameter used in $.ajax call which build <select>. The simplest modification of the original code of jqGrid will be to insert the line

    var rowid = $.jgrid.stripPref($t.p.idPrefix,
            String(options.id).substring(0, String(options.id).length - String(options.name).length - 1));
    

    before the line line of code where $.ajax with dataUrl will be called. Additionally one need to add one more parameter in the $.ajax:

    data: $.isFunction(ajaxso.postData) ?
        ajaxso.postData.call($t, rowid, String(options.name), vl) :
        ajaxso.postData,
    

    After such changes one will be able to use

    ajaxSelectOptions: {
        postData: function (rowid, colName, value) {
            return { id: rowid };
        }
    }
    

    The demo demonstrate that the approach work. You could see in Fiddler, Firebug or in Developer Tools that the option id will be really send to the URL. I’ll post the corresponding suggestion to trirand later (I want to make some additional improvements for more common case)

    If you need to implement the solution with the current version of jqGrid you can do the following instead. You can “subclass” the method $.jgrid.createEl which do the $.ajax request. The implementation will also simple enough:

    var originalCreateEl = $.jgrid.createEl,
        createElementOptions;
    
    $.extend($.jgrid, {
        createEl: function (eltype, options, vl, autowidth, ajaxso) {
            if (options.dataUrl) {
                createElementOptions = options;
            }
            return originalCreateEl.call(this,eltype, ptions,vl,autowidth,ajaxso);
        }
    });
    
    $('#MyGrid').jqGrid({
        ...
        ajaxSelectOptions: {
            data: {
                id: function () {
                    var id = createElementOptions.id,
                        colName = createElementOptions.name;
                    if (typeof id !== "string" || typeof colName !== "string") {
                        return null;
                    }
                    return id.substring(0, id.length - colName.length - 1);
                }
            }
        }
    });
    

    The next demo demonstrate the way.

    UPDATED 2: I posted the pull request to make support of postData as property of ` andajaxSelectOptions`. The request is committed now (see here). So the next version of jqGrid (higher as 4.4.1) will have the functionality “out of the box”.

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

Sidebar

Related Questions

I have a jqGrid defined as such: $(#tableFeedbackReports).jqGrid({ url: '/FeedbackReports/GetFeedbackReport', datatype: 'json', colNames: ['ColA',
I am using jqGrid with treeGrid. I have added a filterToolbar. I would like
I have a jqGrid in an ASP.Net MVC. The grid is defined as: $(#list).jqGrid({
i have a jqgrid treegrid cell and i want to have content inside of
I have jqGrid with two columns, one being hidden. For some reason in FireFox
I have this jqGrid: $(#report).jqGrid( { url: '/py/db?coll=report', datatype: 'json', height: 250, colNames: ['ACN',
I have this problem, treegrid in jqGrid ignores the last option (expanded node or
Hello I have an example that works properly: $(function() { $(#treegrid).jqGrid({ url: 'tree2.json', datatype:
I have jqgrid-treegrid in a system to display all records in the same page
I have a jqgrid with a filterToolbar correctly displaying: jQuery(#myGrid).jqGrid('filterToolbar',{autosearch:true}); I want it to

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.