2015-04-04 64 views
1

我正在寻找一种方式来执行“添加到购物车”ajax调用传递产品代码(行ID)和数量从其他列点击如果在jqgrid列中单击,则行和重定向到购物车页面。如何执行ajax调用和重定向到其他页面,如果点击免费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 
    }); 
} 

addToCartOnClick不jree jqGrid的调用。

在4.6的jqGrid格式化dynamiclink

onClick=addToCartOnClick 

How to pass data to url from jqgrid row if hyperlink is clicked

描述在自由的jqGrid addToCartOnClick工作也不会从dynamicLink格式化器调用。

如何调用方法并从免费jqgrid中点击行获取列值?

回答

2

showAction只能用于设置的URL部分。如果要使用该选项,则必须使用前缀javascript:(请参阅the answer)以启动addToCartOnClick,该功能可以定义为全球功能。

最好是在formatter: "showlink"formatoptions中使用新选项onClick。在阅读完您的问题后,我直接提供了免费jqGrid的代码the corresponding changes。您应该刷新您在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 
     } 
    }} 
+0

谢谢。有效。 – Andrus 2015-04-05 11:25:55

+0

@安德鲁斯:不客气! – Oleg 2015-04-05 13:54:36

相关问题