How to make ajax call and redirect to another page if you click in a free jqgrid column

I am looking for a way to make an “Add to Cart” ajax call to transfer the product code (row identifier) ​​and the quantity from other columns in the pressed row and redirect to the cart page if I click in the jqgrid column.

According to https://github.com/free-jqgrid/jqGrid/wiki/improvement-of-formatter:-"showlink"

Twitter format has improved, so I tried to use it.

I tried colmodel

 {"label":"Add to cart", "name":"Addtocrt_addtocrt","search":false,"sortable":false, "viewable":false,"formatter":"showlink","formatoptions":{"showAction":addToCartOnClick }} 

and method

 function addToCartOnClick(rowId, iRow, iCol, cellValue, e) { var $quantity = $('#' + $.jgrid.jqID(rowId) + '>td:nth-child(' + (iCol + 1) + ')'), quantityVal; if (iCol < 0) { quantityVal = 1; } else if ($quantity.find('>input').length === 0) { quantityVal = $quantity.text(); } else { quantityVal = $quantity.find('>input').val(); } window.location = 'Store/AddToCart?' + $.param({ id: rowId, quantity: quantityVal }); } 

addToCartOnClick is not called in jree jqgrid.

In jqgrid 4.6 dynamic link formatting

 onClick=addToCartOnClick 

worked as described in How to pass data to a URL from a jqgrid string if a hyperlink is clicked

In the free jqgrid addToCartOnClick is also not called from dynamicLink formatting.

How to call a method and get column values ​​from a row with a click in free jqgrid?

+1
javascript jquery ajax jqgrid free-jqgrid
source share
1 answer

showAction can be used to set only part of the URL . You want to use this option, then you must use the javascript: prefix (see answer ) to run addToCartOnClick , which the mast can be defined as global .

It would be better to use the new onClick option in formatoptions of formatter: "showlink" . I made the appropriate changes to the free jqGrid code directly after reading your question. You must update the sources you use on GitHub. Now you can use

 {name: "Addtocrt_addtocrt", label: "Add to cart", search: false, sortable: false, viewable: false, formatter: "showlink", formatoptions: { onClick: function (options) { // object options contains properties, which could be helpful // iCol - index of the column in colModel // iRow - index of the row // rowid // cm - element of colModel // cmName - the same as cm.name // cellValue: the text inside of `<a>` // a - DOM element of clicked <a> // event - Event object of the click event location.href = "http://www.google.com/"; return false; // it important to suppress the default a action } }} 
+2
source share

All Articles