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
});
}
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:
The
urldefined as function will be used in the<a>as the value ofhrefattribute.Additionally to the
urlformatoptionsthe ‘dynamicLink’ formatter supportstargetoption (with the same meaning as by ‘showlink’),cellValuewhich can be also function andonClickcallback withrowId,iRow,iCol,cellValue,eas parameters. If theonClickcallback is defined the value ofurlwill be ignored. So one can skip the definition of the formatter optionurl.The demo demonstrate the usage of the ‘dynamicLink’ formatter:
The current code of the
formatter: 'dynamicLink'you can find below: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 theformatter: "dynamicLink"in case of usage free jqGrid.