jqgrid搜索弹出窗口允许删除所有过滤器!

时间:2011-05-19 20:03:22

标签: jqgrid

我在JqGrid上尝试非常简单的搜索弹出窗口。请参阅下面的代码。问题很少:

  • 弹出窗口会在最顶部显示AND / OR和[+]控件。请参见下面的屏幕截图:(来自FF 4)enter image description here

  • 您可以单击[ - ]按钮删除第一个(也是唯一的)过滤器行。它不应该被允许。绝不允许删除第一个过滤行。

  • 代码:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
     <html>
    <head>
    <title>JQGRID Test</title>      
    <link rel="stylesheet" type="text/css" media="screen" href="http://trirand.com/blog/jqgrid/themes/redmond/jquery-ui-1.8.1.custom.css"/>
    <link rel="stylesheet" type="text/css" media="screen" href="http://trirand.com/blog/jqgrid/themes/ui.jqgrid.css"/>
    
    <script type="text/javascript" src="http://trirand.com/blog/jqgrid/js/jquery.js"></script>
    <script type="text/javascript" src="http://trirand.com/blog/jqgrid/js/jquery-ui-1.8.1.custom.min.js"></script>
    <script type="text/javascript" src="http://trirand.com/blog/jqgrid/js/i18n/grid.locale-en.js"></script>
    <script type="text/javascript" src="http://trirand.com/blog/jqgrid/js/jquery.jqGrid.min.js"></script>
    
    <script type="text/javascript">
        $(function() {
            createGrid();
        });
        function createGrid() {
            $("#jqgrid-table").jqGrid({
                colNames:['First Name', 'Last Name', 'Age', 'IQ', 'Type'],
                colModel:[
                    {name:'firstName',index:'firstName', width:100},
                    {name:'lastName',index:'lastName', width:100},
                    {name:'age', index:'age', width:50},
                    {name:'iq', index:'iq', width:50, stype:'select', searchoptions: {dataUrl:'/api/domains/putcalldomain'}},
                    {name:'type', index:'type', width: 56}
                ],
                width: 800,
                datatype:'local',                   
                pager: '#pager2',
                viewrecords: true,
                caption:"JSON Example"
            });
            var searchOptions = {
                caption: 'Filter...',
                multipleSearch:true,
                closeAfterSearch:true,
                closeAfterReset:true,
                Find: 'Filter'
            };                
            jQuery("#jqgrid-table").jqGrid('navGrid',
                                    '#pager2', 
                                    {search:true, edit:false, add:false, del:false, refresh:false}, 
                                    null, null, null, searchOptions
                                    );
            var data = getData();
            for(var i =0; i < data.length; i++) {
                var r = data[i];
                jQuery("#jqgrid-table").addRowData(r.id, r);
            }
        }
        function getData() {
            return [
                   {id:1, firstName: 'John', lastName: 'XXX',  age:'30',  iq:'200', type: 'Nice'},
                   {id:2, firstName: 'Ashley', lastName:'YYY', age:'31', iq:'210', type:'Nicer'},
                   {id:3, firstName:'Smith', lastName:'ZZZ', age:'23', iq:'90', type:'Nicest'}
                ];
       }
    
    </script>
    </head>
    <body>
      <div id='jqgrid-div'>
          <table id='jqgrid-table'></table>
         <div id="pager2"></div>
      </div>
    </body>
    </html>
    

1 个答案:

答案 0 :(得分:0)

我建议覆盖过滤使用的内部reDraw方法(有关详细说明,请参阅my another answer)。为此,您应该在使用searchOptions事件处理程序的beforeShowSearch中包含以下实现:

beforeShowSearch: function($form) {
    var searchDialog = $form[0],
        oldrReDraw = searchDialog.reDraw, // save the original reDraw method
        doWhatWeNeed = function() {
            $('input.delete-rule:first',searchDialog).unbind('click');

            // set fucus in the last input field
            setTimeout(function() {
               // set fucus in the last input field
               $('input[type="text"]:last',searchDialog).focus();
            }, 50);
        }
    searchDialog.reDraw = function() {
        oldrReDraw.call(searchDialog);    // call the original reDraw method
        doWhatWeNeed();
    }
    doWhatWeNeed();
}

您可以看到相应的演示here