Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用Search Diaglog上的自定义按钮保存Jqgrid的搜索过滤器_Php_Jquery_Jqgrid_Advanced Search - Fatal编程技术网

Php 使用Search Diaglog上的自定义按钮保存Jqgrid的搜索过滤器

Php 使用Search Diaglog上的自定义按钮保存Jqgrid的搜索过滤器,php,jquery,jqgrid,advanced-search,Php,Jquery,Jqgrid,Advanced Search,我在jqgrid的搜索对话框中添加了一个按钮,用于在数据库中保存搜索条件,并在以后使用它。 单击该按钮,我需要搜索条件的过滤器属性jqgrid [快照] 当用户单击“保存”按钮时,我在搜索对话框中添加了自定义按钮,我使用对话框询问过滤器名称,然后将其和过滤器一起保存 单击“搜索”按钮时,我不希望根据搜索条件重新加载网格 但我无法将筛选器属性存储在数据库中 我使用了afterRedraw事件,但这不是我添加的最后一个过滤器 所以请尽快回复我 提前谢谢 var grid = jQuery("#li

我在jqgrid的搜索对话框中添加了一个按钮,用于在数据库中保存搜索条件,并在以后使用它。 单击该按钮,我需要搜索条件的过滤器属性jqgrid

[快照] 当用户单击“保存”按钮时,我在搜索对话框中添加了自定义按钮,我使用对话框询问过滤器名称,然后将其和过滤器一起保存

单击“搜索”按钮时,我不希望根据搜索条件重新加载网格

但我无法将筛选器属性存储在数据库中

我使用了afterRedraw事件,但这不是我添加的最后一个过滤器

所以请尽快回复我

提前谢谢

var grid = jQuery("#list_records").jqGrid({
        url: "getGridData.php?" + window.location.search.substring(1),
        searchurl: "getGridData.php?" + window.location.search.substring(1),
        datatype: 'json',
        mtype: "GET",
        colNames: ["Task Id", "Title", "Priority", "tags", "Created Date", "Last Update Date", "Complete Date"],
        colModel: [
                    { name: 'Task_ID', index: 'Task_ID', width: 200},
                    { name: 'Title', index: 'Title', width: 200 },
                    { name: 'Priority', index: 'Priority', width: 200},
                    { name : 'tags', index : 'tags', width : 200},
                    { name : 'Created_Date', index : 'Created_Date', width : 200},
                    { name : 'Last_Updated', index : 'Last_Updated', width : 200},
                    { name : 'Completed_date', index : 'Completed_date', width : 200}
                ],
        sortname: 'Task_ID',
        viewrecords: true,
        rownumbers: true,
        sortorder: "desc",
        ignoreCase: true,
        pager: '#perpage',
        caption: "Task Results",
        rowNum: 30,
        ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
        });

grid.jqGrid('navGrid','#perpage', {add:false,edit:false,del:false,search:false,refresh:false}).jqGrid('navButtonAdd','#perpage',{
               caption: "",
               title : "Search",
               id : "filterManipulation",
               buttonicon:"ui-icon-search", 
               onClickButton: function (){
                    //console.log(JSON.stringify(filterForSearch));
                    $("#list_records").setGridParam({
                         postData: { filters: JSON.stringify(filterForSearch)}
                    });

                    $("#list_records").jqGrid('searchGrid', 
                        {multipleSearch:true, overlay:false, searchOnEnter:true, multipleGroup:true, closeOnEscape:true, showQuery:true,recreateFilter: true,
                        afterShowSearch : function(){
                            var element = document.getElementById("fbox_list_records_2").getElementsByTagName("tr")[1].getElementsByTagName("td")[1];
                            var saveAnchor = document.createElement('a');
                            saveAnchor.setAttribute('id', 'fbox_list_save_query');
                            saveAnchor.setAttribute('class', 'fm-button ui-state-default ui-corner-all fm-button-icon-left');
                            saveAnchor.setAttribute('onclick','saveSearch()');
                            saveAnchor.innerHTML = buttonName;
                            var newAnchor = document.createElement('a');
                            newAnchor.setAttribute('id', 'fbox_list_new_filter');
                            newAnchor.setAttribute('class', 'fm-button ui-state-default ui-corner-all fm-button-icon-left');
                            newAnchor.setAttribute('onclick','newFilter()');
                            newAnchor.innerHTML = 'New';
                            element.appendChild(newAnchor);
                            element.appendChild(saveAnchor);                    

                            var tableDataTag = document.createElement("td");
                            tableDataTag.setAttribute('id','tdForFilterNameList');
                            var filterNameList = document.createElement("select");
                            filterNameList.setAttribute('id','filterNameList');
                            filterNameList.setAttribute('onChange','loadFilterAttribute()');
                            var option = new Option("--Select--", "0");
                            filterNameList.appendChild(option);
                            <?php
                                $userId = 0;
                                $conn = new mysqli("localhost", "root", "$$$$", "$$$");
                                if (mysqli_connect_errno()){
                                    echo "Failed to connect to MySQL: " . mysqli_connect_error();
                                }
                                $sql = "select filter_id,filter_name from filters where userID = $userId ";
                                //print $sql;
                                $result = $conn->query($sql);
                                if($result)
                                {
                                    while ($row = $result->fetch_assoc()) {
                            ?>
                                        var optionTag = document.createElement("option");
                                        optionTag.setAttribute("value", "<?php echo $row['filter_id']?>");
                                        var text = document.createTextNode("<?php echo $row['filter_name']?>");
                                        optionTag.appendChild(text);
                                        if(selectedValue == "<?php echo $row['filter_id']?>"){
                                            optionTag.setAttribute("Selected", "true");
                                        }
                                        //option = new Option('<?php echo $row['filter_name']?>', '<?php echo $row['filter_id']?>');
                                        filterNameList.appendChild(optionTag);
                            <?php 
                                    }
                                }
                            ?>
                            tableDataTag.appendChild(filterNameList);
                            var elementForDropDown = document.getElementById("fbox_list_records").getElementsByTagName("table")[0].getElementsByTagName("tr")[0];
                            elementForDropDown.appendChild(tableDataTag);
                        },
                        onSearch: function() {
                            var postData = grid.jqGrid('getGridParam','postData');
                            var $filter = $("#" + $.jgrid.jqID("fbox_" + this.id)),
                            sql = $filter.jqFilter('toSQLString');
                            $("#list_records").setGridParam({url: "getGridData.php?" + window.location.search.substring(1) + "&sqlQuery=" + escape(sql)});
                            $("#list_records").trigger("reloadGrid");
                            loadgridData(postData, sql);    
                            fusionChart(postData, sql); 
                            return false;
                        }, 
                        onReset : function() {
                            var postData = grid.jqGrid('getGridParam','postData');
                            $("#list_records").setGridParam({url: "getGridData.php?" + window.location.search.substring(1)});
                            $("#list_records").trigger("reloadGrid");
                            loadgridData(postData, ''); 
                            fusionChart(postData, '');  
                            return false;
                        },
                        onClose: function(){
                            filterForSearch = "";
                            buttonName = "Save";
                            selectedValue = "";
                        },
                        afterRedraw: function (p) {
                            console.log(p.filter);
                        }
                    });
                }, 
               position:"last"
        });
在上面的代码中,我添加了自定义导航按钮。 此代码用于加载用户的搜索筛选器。 存储和编辑过滤器的方法

但我应该做什么才能在单击“保存”按钮的位置获取过滤器呢


感谢@jtc审查我的问题。 我的问题的答案已经在我的问题中了

基本上,我已经实现了保存,更新,删除功能,提前搜索对话框

在搜索对话框中,我列出了特定用户的所有过滤器

用户可以创建新过滤器,也可以通过选择过滤器来更新和删除过滤器

所以,稍后当用户再次登录时,他/她对过滤器进行了所有操作,并从过滤器列表中选择特定字段,并相应地执行搜索

因此,如果有人需要此功能的代码,请告诉我


谢谢

一些实际的代码/小提琴会很有用。@JTC这是足够的解释还是你需要更多的东西?对不起,我还是不太明白你需要什么。您通过ajax获得serach,用户可以单击保存,然后您试图获取他使用的最后一个输入,或者什么?请更具体一点,这样我们可以尽力帮助你。搜索很有效。请参阅图片链接。如果用户添加过滤器并直接单击我按专业语法添加的save按钮,那么我希望将过滤器属性的json sting存储在数据库中。示例:{groupOp:AND,规则:[{field:Priority,op:cn,data:hi},{field:Task_ID,op:cn,data:59}]}。这种字符串存储在数据库中,用于各自的过滤器。希望这有帮助。否则请告诉我。搜索与保存不同。当通过单击“+”或“-”按钮使用添加规则,然后单击保存按钮时,我需要将JSON格式的过滤器的数据存储在数据库中。但过滤器属性仅在重新加载网格或单击搜索按钮时设置。我不想要的。