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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:47:30+00:00 2026-05-29T05:47:30+00:00

jqGrid contains quantity column and add to cart button using colmodel below. Inline editing

  • 0

jqGrid contains quantity column and add to cart button using colmodel below. Inline editing
is used to fill quantity.
If quantity is fileld and add to cart link on other column is clicked, entered quanty is not passed to AddToCart controller. Product id from id field in json data is passed correctly.

How to pass selected quantity to AddToCart controller (using invoked url query string or something other) ?

colmodel is:

{"label":"AddToCart",
 "name":"Addtocrt_addtocrt",
 "formatter":"showlink",
 "formatoptions": {"baseLinkUrl":"http://MySite.com/Store/AddToCart"}
 },

{"label":"Quantity",
  "name":"Stocks_valkogus",
  "editoptions":{"maxlength":10 }
  "editable":true
   }

Update

Data from server is in json format and row editing mode is used.
rowData.Stocks_valkogus returns undefined.

I tried code below. alert box shows that quantityVal is undefined.
How to retrieve entered quantity?

{"name":"Addtocrt_addtocrt",
 "formatter":"dynamicLink",
 "formatoptions":{"onClick":addToCartOnClick
}}

function addToCartOnClick(rowId, iRow, iCol, cellValue, e) {
    var iCol = getColumnIndexByName($grid, 'Stocks_valkogus') ,
       quantityVal = $('#' + $.jgrid.jqID(rowId) + '>td:nth-child(' + (iCol + 1) + '>input').val();
    alert(iCol); // returns 3 
    alert(quantityVal); // returns undefined. 
    window.location = 'Store/Details?' + $.param({
        id: rowId,
        quantity: quantityVal
    });
}
  • 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-29T05:47:31+00:00Added an answer on May 29, 2026 at 5:47 am

    I understand the problem very good. I agree that both predefined formatter which one can use currently (‘showlink’ and ‘link’ formatters) are not flexible enough.

    I can suggest you another formatter which you could download here. The usage of the formatter is very easy:

    {label: "AddToCart", name: "Addtocrt_addtocrt", formatter: "dynamicLink",
        formatoptions: {
            url: function (cellValue, rowId, rowData) {
                return '/Store/AddToCart' + rowId + '?' +
                    $.param({
                        quantity: rowData.Stocks_valkogus
                    });
            }
        }
    }
    

    The url defined as function will be used in the <a> as the value of href attribute.

    Additionally to the url formatoptions the ‘dynamicLink’ formatter supports target option (with the same meaning as by ‘showlink’), cellValue which can be also function and onClick callback with rowId, iRow, iCol, cellValue, e as parameters. If the onClick callback is defined the value of url will be ignored. So one can skip the definition of the formatter option url.

    The demo demonstrate the usage of the ‘dynamicLink’ formatter:

    enter image description here

    The current code of the formatter: 'dynamicLink' you can find below:

    /*global jQuery */
    (function ($) {
        'use strict';
        /*jslint unparam: true */
        $.extend($.fn.fmatter, {
            dynamicLink: function (cellValue, options, rowData) {
                // href, target, rel, title, onclick
                // other attributes like media, hreflang, type are not supported currently
                var op = {url: '#'};
    
                if (typeof options.colModel.formatoptions !== 'undefined') {
                    op = $.extend({}, op, options.colModel.formatoptions);
                }
                if ($.isFunction(op.target)) {
                    op.target = op.target.call(this, cellValue, options.rowId, rowData, options);
                }
                if ($.isFunction(op.url)) {
                    op.url = op.url.call(this, cellValue, options.rowId, rowData, options);
                }
                if ($.isFunction(op.cellValue)) {
                    cellValue = op.cellValue.call(this, cellValue, options.rowId, rowData, options);
                }
                if ($.fmatter.isString(cellValue) || $.fmatter.isNumber(cellValue)) {
                    return '<a' +
                        (op.target ? ' target=' + op.target : '') +
                        (op.onClick ? ' onclick="return $.fn.fmatter.dynamicLink.onClick.call(this, arguments[0]);"' : '') +
                        ' href="' + op.url + '">' +
                        (cellValue || '&nbsp;') + '</a>';
                } else {
                    return '&nbsp;';
                }
            }
        });
        $.extend($.fn.fmatter.dynamicLink, {
            unformat: function (cellValue, options, elem) {
                var text = $(elem).text();
                return text === '&nbsp;' ? '' : text;
            },
            onClick: function (e) {
                var $cell = $(this).closest('td'),
                    $row = $cell.closest('tr.jqgrow'),
                    $grid = $row.closest('table.ui-jqgrid-btable'),
                    p,
                    colModel,
                    iCol;
    
                if ($grid.length === 1) {
                    p = $grid[0].p;
                    if (p) {
                        iCol = $.jgrid.getCellIndex($cell[0]);
                        colModel = p.colModel;
                        colModel[iCol].formatoptions.onClick.call($grid[0],
                            $row.attr('id'), $row[0].rowIndex, iCol, $cell.text(), e);
                    }
                }
                return false;
            }
        });
    }(jQuery));
    

    I plan to place the code of the formatter and some other plugins to jqGrid on the github.

    UPDATED: Free jqGrid extends the options of formatter: "showlink" (see the wiki article and the answer). So one don’t need to use the formatter: "dynamicLink" in case of usage free jqGrid.

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

Sidebar

Related Questions

jqGrid add forms contains autocomplete boxes using code below. If new row is added
Code below from other stackoverflow answer is used in jqGrid to implement checkbox using
jqgrid doc in here contains: method allow to reorder the grid columns using the
I am using jqgrid. My page has three tabs and each tab contains a
I defined inline-editing for my grid, which contains some checkbox columns, and it works
jqGrid delete action button is used to delete row. This button click calls Edit
jqGrid Edit form invoked using Edit button from top toolbar is defined as grid.navGrid(#grid_toppager,
My jqgrid contains several pages. When I sort any column the page resets to
jqGrid inline edit starts on single in click by onSelectRow event below. Save and
I have a jqgrid that contains some data, the first column of which is

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.