JqG​​rid中的日期范围

时间:2015-10-09 08:52:12

标签: javascript jquery jqgrid daterangepicker

我必须通过DateRangePicker元素过滤日期来获取我的jqgrid中的过滤行。

我不想要任何过滤窗口。

这是我的jsfiddle jqgrid code。它仅适用于一个日期,但不适用于日期范围。

<script type="text/javascript">
//<![CDATA[
    jQuery(document).ready(function () {
        var mydata = [
            {id:"1", invdate:"2015-10-01",name:"test",  note:"note",  amount:"200.00",tax:"10.00",total:"210.00"},
            {id:"2", invdate:"2015-10-02",name:"test2", note:"note2", amount:"300.00",tax:"20.00",total:"320.00"},
            {id:"3", invdate:"2015-09-01",name:"test3", note:"note3", amount:"400.00",tax:"30.00",total:"430.00"},
            {id:"4", invdate:"2015-10-04",name:"test4", note:"note4", amount:"200.00",tax:"10.00",total:"210.00"},
            {id:"5", invdate:"2015-10-05",name:"test5", note:"note5", amount:"300.00",tax:"20.00",total:"320.00"},
            {id:"6", invdate:"2015-09-06",name:"test6", note:"note6", amount:"400.00",tax:"30.00",total:"430.00"},
            {id:"7", invdate:"2015-10-04",name:"Test7", note:"note7", amount:"200.00",tax:"10.00",total:"210.00"},
            {id:"8", invdate:"2015-10-03",name:"test8", note:"note8", amount:"300.00",tax:"20.00",total:"320.00"},
            {id:"9", invdate:"2015-09-01",name:"test9", note:"note9", amount:"400.00",tax:"30.00",total:"430.00"},
            {id:"10",invdate:"2015-09-08",name:"test10",note:"note10",amount:"500.00",tax:"30.00",total:"530.00"},
            {id:"11",invdate:"2015-09-08",name:"Test11",note:"note11",amount:"500.00",tax:"30.00",total:"530.00"},
            {id:"12",invdate:"2015-09-10",name:"test12",note:"note12",amount:"500.00",tax:"30.00",total:"530.00"}
        ];

var myGrid = $("#list");
myGrid.jqGrid({
datatype: "local",
data: mydata,
colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
colModel:[
      {name:'id',index:'id', width:65, sorttype: 'int'},
      {name:'invdate',index:'invdate', width:120, align:'center', sorttype:'date',
         formatter:'date', formatoptions: {newformat:'m/d/Y'},
         searchoptions: {
            sopt: ['eq','ne'],
            dataInit : function (elem) {
                   $(elem).daterangepicker({ 
                    dateFormat:'m/d/y', 
                    onClose: function(event) {
                           //$("#list")[0].triggerToolbar();
                           $('#list').trigger('reloadGrid');
                    }                                               
         });  
}}},
   {name:'name',index:'name', width:90},
                    {name:'amount',index:'amount', width:70, formatter:'number', align:"right"},
                    {name:'tax',index:'tax', width:60, formatter:'number', align:"right"},
                    {name:'total',index:'total', width:60, formatter:'number',align:"right"},
                    {name:'note',index:'note', width:100, sortable:false}
                ],
                rowNum:10,
                rowList:[5,10,20],
                pager: '#pager',
                ignoreCase:true,
                sortname: 'invdate',
                viewrecords: true,
                sortorder: "desc",
                caption:"Sorting and paging of local data",
                height: "100%"
            }).jqGrid('navGrid','#pager',{add:false,edit:false,del:false});
            myGrid.filterToolbar();
        });
    //]]>
    </script>
</head>
<body>
<table id="list"><tr><td/></tr></table>
<div id="pager"/>
</body>

我也注意到在我的jsfiddle中,在datearangepicker日历中选择值之后,我必须按Enter来过滤网格中的值。虽然我的onClose daterangepicker方法中有一些代码,如下所示

 dataInit : function (elem) {
         $(elem).daterangepicker({ 
             dateFormat:'m/d/y', 
              onClose: function(event) {
                   $('#list').trigger("reloadGrid",[{page:1}]);
              }
         });
 }  

1)点击日期的过滤器输入框,我看到日历并能够选择日期范围。 即10/1/15 - 10/10/15。但是使用此输入,只有一行出现在Date 10/1/15。结果不出现在10/1 - 10/10之间。

2)选择日期后,使用以下代码尝试不刷新网格。

$("#list")[0].triggerToolbar();
$('#list').trigger('reloadGrid');

任何人都可以帮助。感谢

0 个答案:

没有答案