jqGrid的jQuery的按钮点击刷新只有一次射击 [英] jQuery button click refresh of jqGrid only firing once

查看:131
本文介绍了jqGrid的jQuery的按钮点击刷新只有一次射击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我使用填充一个jqGrid的下列哪些jQuery的code。它完美的作品发布到我的ASP.NET MVC页面上的按钮的第一次点击。我的

问题是,任何其他点击过去的第一似乎通过了jQuery code运行单击该按钮时,但它从来没有因此导致的POST页。任何想法,为什么?

 <脚本类型=文/ JavaScript的>        $(文件)。就绪(函数(){
            $('#btnSubmit按钮')。点击(函数(){                / *刷新电网* /
                $(#清单)。jqGrid的({
                    / *控制器动作从*获得网格数据/
                    网址:'/ CRA / AddPart',
                    数据:{部分号码:123},
                    数据类型:JSON,
                    MTYPE:'GET',
                    / *定义对电网*头/
                    colNames:['COL1','COL2','COL3','COL4'],
                    / *定义哪些字段行列来自* /
                    colModel:
                  {名称:'COL1',索引:因维',宽度:290},
                  {名称:'COL2',索引:invdate',宽度:290},
                  {名称:'COL3',索引:'量',宽度:290,排列:正确},
                  {名称:'COL4',索引:'税',宽度:290,对齐:'右'}],
                    高度:'自动',
                    的rowNum:10,
                    rowList:[10,20,30],
                    sortname:'ID',
                    排序顺序:递减,
                    viewrecords:真实,
                    imgpath:../../Scripts/jgrid/themes/steel/images',
                    标题:核心退货授权内容:,
                    cellEdit:真
                });
            });
        });    < / SCRIPT>


解决方案

电网未重装的原因是,您所呼叫的错误的方法。该方法的jqGrid大约做到这一点:


  1. 检查表,看它是否已经是一个网格;如果是这样,退出。

  2. 打开表成一个网格。

  3. 填充数据的第一页。

所以,你调用该方法的第二次,它什么都不做,按照步骤1。

相反,你应该叫 $(#清单)。触发(reloadGrid)在第二和所有后续点击。

现在,因为在网格选项您MTYPE的,网格是打算做一个GET,而不是POST。因此,如果该信息是从按钮本身来(换句话说,这是提交类型的输入),你应该返回true,表明提交应该继续像往常一样。

I have the following jQuery code which I'm using to populate a jqGrid. It works perfectly posting to my ASP.NET MVC page on the first click of the button. My
problem is, any other clicks past the first it seems to run through the jquery code when clicking the button but it never makes it to the POST page. Any ideas why?

<script type="text/javascript">

        $(document).ready(function() {
            $('#btnSubmit').click(function() {

                /* Refreshes the grid */
                $("#list").jqGrid({
                    /* The controller action to get the grid data from */
                    url: '/CRA/AddPart',
                    data: { partNumber: "123"},
                    datatype: 'json',
                    mtype: 'GET',
                    /* Define the headers on the grid */
                    colNames: ['col1', 'col2', 'col3', 'col4'],
                    /* Define what fields the row columns come from */
                    colModel: [
                  { name: 'col1', index: 'invid', width: 290 },
                  { name: 'col2', index: 'invdate', width: 290 },
                  { name: 'col3', index: 'amount', width: 290, align: 'right' },
                  { name: 'col4', index: 'tax', width: 290, align: 'right'}],
                    height: 'auto',
                    rowNum: 10,
                    rowList: [10, 20, 30],
                    sortname: 'id',
                    sortorder: "desc",
                    viewrecords: true,
                    imgpath: '../../Scripts/jgrid/themes/steel/images',
                    caption: 'Core Return Authorization Contents:',
                    cellEdit: true
                });
            });
        });

    </script>

解决方案

The reason the grid isn't reloading is that you are calling the wrong method. The jqGrid method does approximately this:

  1. Examine the table to see if it is already a grid; if so, exit.
  2. Turn the table into a grid.
  3. Populate the first page of data.

So the second time you call the method, it does nothing, as per step 1.

Instead, you should be calling $("#list").trigger("reloadGrid") on the second and all subsequent clicks.

Now, because of your mtype in the grid options, the grid is going to do a GET, not a POST. So if the POST is coming from the button itself (in other words, it is an input of type submit), you should return true to indicate that the submit should continue as usual.

这篇关于jqGrid的jQuery的按钮点击刷新只有一次射击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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