【问题标题】:jqgrid data loading in a button click everytimejqgrid数据加载按钮每次点击
【发布时间】:2014-05-08 10:55:49
【问题描述】:

我正在使用下面的代码在按钮单击后加载 jqgrid 数据。当我第一次单击按钮时,这是有效的。而我第二次单击该按钮意味着它没有加载。请帮我解决这个问题。

 <script type="text/javascript">

        $(document).ready
        (
            function () {
                $('#btnContinue').live('click', function () {
                    var parent =  $('#hf_val').val();   
                        bindCustomers(parent);
                });
            }
        );

        var bindCustomers = function () {
            alert('in');
            // Set up the jquery grid
            $("#jqTable").jqGrid
                (
                    {
                        // Ajax related configurations
                        url: 'LoadCustomerData.ashx?TypeId='+ parent,
                        datatype: "json",
                        mtype: "POST",

                        // Specify the column names
                        colNames: ["CustomerId", "FirstName", "LastName"],

                        // Configure the columns
                        colModel: [
                                { name: "CustomerId", index: "CustomerId", width: 40, align: "left" },
                                { name: "FirstName", index: "FirstName", width: 100, align: "left" },
                                { name: "LastName", index: "LastName", width: 200, align: "left"}],

                        // Grid total width and height
                        width: 550,
                        height: 200,

                        // Paging
                        toppager: true,
                        pager: $("#jqTablePager"),
                        rowNum: 5,
                        rowList: [5, 10, 20],
                        viewrecords: true, // Specify if "total number of records" is displayed

                        // Default sorting
                        //sortname: "Id",
                        //sortorder: "asc",

                        // Grid caption
                        caption: "A Basic jqGrid - Read Only"
                    }
                ).navGrid("#jqTablePager",
                    { refresh: true, add: false, edit: false, del: false },
                        {}, // settings for edit
                        {}, // settings for add
                        {}, // settings for delete
                        {sopt: ["cn"]} // Search options. Some options can be set on column level
                );
            alert('loading finish');
        }
    </script>

【问题讨论】:

  • 不要使用 .live,使用 .on
  • 第二次加载时控制台是否出现错误?
  • 不,我没有收到任何错误
  • @user3036342 这不是问题。事件每次都正确触发。
  • 但是网格内容 url 没有被触发..

标签: jquery jqgrid jqgrid-asp.net jqgrid-php


【解决方案1】:

好的,我知道你的问题出在哪里。这样,您每次都尝试重新创建整个网格,而不仅仅是重新加载数据。

您是通过 URL 进行的(我建议将数据 POST 到 URL,而不是注入攻击的机会)

而不是每次(或尝试)都重新创建它,只需在点击时调用它:

$("#jqTable").setGridParam({'postData': data});

“数据”类似于 'TypeId=' + parent

【讨论】:

    【解决方案2】:

    在函数外部创建网格,在 onclick 内部重新加载网格。您不必每次单击时都创建整个网格。变量 parent 可以添加到 postdata。

    【讨论】:

      猜你喜欢
      • 2016-05-14
      • 1970-01-01
      • 2019-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-22
      • 2011-10-20
      • 1970-01-01
      相关资源
      最近更新 更多