我正在寻找一种方法来执行“添加到购物车”ajax 调用以传递产品代码(行 ID)和点击行中其他列的数量,如果在 jqgrid 列中点击则重定向到购物车页面。
根据
https://github.com/free-jqgrid/jqGrid/wiki/improvement-of-formatter:-"showlink"
showlink 格式化程序得到了改进,所以我尝试使用它。
我试过colmodel
{"label":"Add to cart",
"name":"Addtocrt_addtocrt","search":false,"sortable":false,
"viewable":false,"formatter":"showlink","formatoptions":{"showAction":addToCartOnClick
}}
和方法
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
});
}
jree jqgrid中没有调用addToCartOnClick
在 jqgrid 4.6 动态链接格式化程序中
onClick=addToCartOnClick
按照 How to pass data to url from jqgrid row if hyperlink is clicked 中的描述工作
在免费的 jqgrid 中,addToCartOnClick 也不会从 dynamicLink 格式化程序中调用。
如何在免费的jqgrid中调用方法并从点击的行中获取列值?
最佳答案
showAction
仅可用于设置URL 部分。如果您想使用该选项,则必须使用 javascript:
前缀(参见 the answer )开始 addToCartOnClick
哪个桅杆被定义为全局函数。
最好使用新选项 onClick
在 formatoptions
的 formatter: "showlink"
.我做了 the corresponding changes阅读您的问题后直接获取免费 jqGrid 的代码。您应该从 GitHub 刷新您使用的来源。现在你可以使用
{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's important to suppress the default a action
}
}}
关于javascript - 如果在免费的 jqgrid 列中单击,如何执行 ajax 调用并重定向到其他页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29450773/