如何执行AJAX调用,并重定向到其他页面,如果点击的免费jqGrid的列 [英] How to perform ajax call and redirect to other page if clicked in free jqgrid column

查看:192
本文介绍了如何执行AJAX调用,并重定向到其他页面,如果点击的免费jqGrid的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找一种方式来执行加入购物车ajax调用为合格产品code(行ID),数量从点击行等栏目,并重定向到购物车页面,如果点击在jqGrid的列。

I'm looking for a way to perform "Add to cart" ajax call to pass product code (row id) and quantity from other columns in clicked row and redirect to cart page if clicked in jqgrid column.

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

showlink格式的改进,所以我尝试使用它。

showlink formatter is improved so I tried to use it.

我想colmodel

I tried 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的。

addToCartOnClick is not called in jree jqgrid.

在jqGrid的4.6 dynamiclink格式化

In jqgrid 4.6 dynamiclink formatter

onClick=addToCartOnClick 

曾在<一个描述href="http://stackoverflow.com/questions/9038063/how-to-pass-data-to-url-from-jqgrid-row-if-hyperlink-is-clicked">How到如果单击超链接从jqGrid的行数据传递到网址

worked as described in How to pass data to url from jqgrid row if hyperlink is clicked

在免费jqGrid的addToCartOnClick也不会从dynamicLink格式调用。

In free jqgrid addToCartOnClick is also not called from dynamicLink formatter.

如何调用方法,并从点击行获得自由jqGrid的列中的值?

How to call method and get column values from clicked row in free jqgrid?

推荐答案

的showAction 可用于将 URL的一部分只。它要使用的选项,那么你必须使用的javascript: preFIX(见的答案)启动 addToCartOnClick 这桅杆被定义为在全球的功能。

showAction can be used to set the part of URL only. It you want to use the option then you have to use javascript: prefix (see the answer) to start addToCartOnClick which mast be defined as the global function.

更好的办法是在 formatoptions 的格式使用新选项的onClick : showlink。我做了相应的变化免费jqGrid的阅读后直接code对你的问题。你应该刷新你从GitHub上使用的音源。现在你可以使用

The better would be to use new option onClick in formatoptions of formatter: "showlink". I made the corresponding changes of the code of free jqGrid directly after reading of your question. You should refresh the sources which you use from 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's important to suppress the default a action
        }
    }}

这篇关于如何执行AJAX调用,并重定向到其他页面,如果点击的免费jqGrid的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆