javascript - 单击按钮后 JqGrid 不会重新加载

标签 javascript jquery jqgrid reload

我在我的项目中使用 jqGrid,我有一个问题,即使在阅读了关于同一主题的论坛后似乎也无法解决。

当用户在选择日期后单击按钮时,我会重新加载网格。我要流量充值通讯员选择日期。

我使用以下代码:

var loadfacture  = false;

    $('#btn-facture').click(function(){     

        if(!loadfacture){           

            $("#factures").jqGrid({
                url:'loadfactureencours.json',
                datatype: "json",           
                autowidth: true,
                height:250,
                colNames:['#','Numero','Date', 'Client','Serveur','Prix Total','Avance','Regler','Notes'],
                colModel:[
                    {name:'idfac',index:'idfac', width:45,align:"center"},
                    {name:'numfac',index:'numfac', width:80,align:"center"},
                    {name:'datefac',index:'datefac', width:150,align:"center"},
                    {name:'client',index:'client', width:145,align:"center"},
                    {name:'utilisateur',index:'utilisateur', width:125,align:"center"},                     
                    {name:'montant',index:'montant', width:70,align:"center"},
                    {name:'avance',index:'avance', width:60,align:"center"},
                    {name:'regler',index:'regler', width:50,align:"center"},
                    {name:'description',index:'description', width:150, sortable:false}
                ],
                rowNum:10,
                rowTotal: 2000,
                rowList : [10,20,30,40,50,60],
                loadonce:true,
                mtype: "GET",
                postData: {
                    day: function () {                      
                        return $('#daySelect').val();
                    }
                },
                rownumbers: false,
                rownumWidth: 40,
                gridview: true,
                pager: '#paging',
                sortname: 'idfac',  
                viewrecords: true,
                sortorder: "desc",
                caption: "",
                ondblClickRow: function(rowid,iRow,iCol,e){
                    var rowData = jQuery(this).getRowData(rowid);
                    console.log(rowData);
                    window.location = "ecrancommandebar.html?num="+rowData.numfac;
                }
            });

            $("#factures").jqGrid('navGrid','#paging',{del:false,add:false,edit:false});
            loadfacture  = true;


        }else{          

            var grid = $("#factures");
                   grid.trigger("reloadGrid",[{current:true}]);

        }

    });

我通过阅读关于同一主题的论坛来构建这段代码,但是第一次加载网格然后当我在更改日期后单击按钮时没有任何反应。

你怎么了?感谢您的反馈。

最佳答案

您使用 loadonce:true 选项将 datatype 从初始 "json" 更改为 "local"第一次从服务器加载数据。它允许支持数据的本地排序、分页和过滤。因此,您应该了解 grid.trigger("reloadGrid",[{current:true}]); 只会重新加载先前保存的响应中的数据。因此,在您将 datatype 参数的值重置为 "json" 之前,不会从服务器重新加载。换句话说,您应该将 else 部分重写为以下内容

...
} else {          
    $("#factures").jqGrid("setGridParam", {datatype: "json"})
        .trigger("reloadGrid", [{current: true, page: 1}]);
}

关于javascript - 单击按钮后 JqGrid 不会重新加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19375610/

相关文章:

具有常见缓动功能的 jQuery 动画队列

javascript - 什么是广告回传标签以及常见实现

javascript - 递归 setTimeout 模式

javascript - XPath 错误。节点不能用于创建它的文档以外的文档中

javascript - 选择大于和小于某些动态值的单元格

php - jQuery jQGrid 在标题层单击时展开/折叠网格

html - 表体设计不匹配

jquery - jqGrid 自定义 edittype(单选按钮列)自定义元素在编辑时不触发 set 事件

javascript - 如何从 PHP 和 JavaScript 中的图像目录中预览选定的图像

javascript - 创建我自己的类似于暗黑破坏神 3 旅程追踪器的 Web 应用程序时遇到问题