2013-01-31 129 views
4

我的数据在服务器端,我编写了代码来执行所有搜索/过滤/排序。jqGrid,搜索日期

我的jqGrid有一个filterToolbar和一个搜索按钮。

不幸的是,当我搜索时,我选择的日期值不会在请求中发送。然而,奇怪的是,它会在filterToolbar的选定日期发送它?!?

这里为什么没有数据?

{"groupOp":"AND","rules":[{"field":"RunDate","op":"le","data":""}]}

这里是我的电网码。

var loadFileInfoList = function (fileInfoList, pager) { 
    fileInfoList.jqGrid({ 
     url: 'GetFiles', 
     datatype: 'json', 
     mtype: 'POST', 
     colNames: ['Id', 'Name', 'Interface', 'Amount', 'Type', 'Created', 'Status'], 
     colModel: [ 
       { jsonmap: 'Id', name: 'Id', formatter: 'integer', align: 'right', hidden: true }, 
       { jsonmap: 'Name', name: 'Name', align: 'right', hidden: true }, 
       { jsonmap: 'InterfaceName', name: 'InterfaceName', align: 'left', width: '100%', sorttype: 'text', frozen: true, 
        search: true, 
        searchoptions: { 
         sopt: ['cn'] 
        } 
       }, 
       { jsonmap: 'Amount', name: 'Amount', formatter: 'currency', align: 'right', width: '100%', sorttype: 'number', 
        search: true, 
        searchoptions: { 
         sopt: ['ge', 'le'] 
        } 
       }, 
       { jsonmap: 'Type', name: 'Type', align: 'right', width: '100%', sorttype: 'text', 
        search: true, stype: 'select', 
        searchoptions: { 
         value: getTypeFilterOptions(), 
         sopt: ['eq'] 
        } 
       }, 
       { jsonmap: 'RunDate', name: 'RunDate', formatter: 'date', align: 'right', width: '100%', sorttype: 'date', 
        search: true, 
        datefmt: 'dd/mm/yyyy', 
        searchrules: { 
         date: true 
        }, 
        searchoptions: { 
         sopt: ['ge', 'le'], 
         dataInit: function (elem) { 
          $(elem).datepicker({ 
           dateFormat: 'dd/mm/yy', 
           changeYear: true, 
           changeMonth: true, 
           showButtonPanel: true, 
           onSelect: function() { 
            $(this).keydown(); 
           } 
          }); 
         } 
        } 
       }, 
       { jsonmap: 'Status', name: 'Status', align: 'right', width: '100%', sorttype: 'text', formatter: formatStatus, 
        search: true, stype: 'select', 
        searchoptions: { 
         value: getStatusFilterOptions(), 
         sopt: ['eq'] 
        } 
       } 
      ], 
     autoencode: true, 
     sortname: 'RunDate', 
     sortorder: 'desc', 
     pager: pager, 
     rowNum: 5, 
     viewrecords: true, 
     height: '100%', 
     autowidth: true, 
     ignoreCase: true, 
     jsonReader: { 
      repeatitems: false, 
      root: "rows" 
     }, 
     altRows: true, 
     altclass: 'jqGridAltRow', 
     loadComplete: function() { 
      $("tr.jqgrow:odd").addClass('jqGridAltRow'); 
     } 
    }); 

    fileInfoList.jqGrid('navGrid', pager, 
     { edit: false, add: false, del: false }, 
     {}, 
     {}, 
     {}, 
     { closeOnEscape: true, closeAfterSearch: true, multipleSearch: true, multipleGroup: false } 
    ); 

    fileInfoList.jqGrid('filterToolbar', { searchOnEnter: false, enableClear: true, stringResult: true }); 
}; 

loadFileInfoList($('#jqgFileInfoList'), '#jqgPagerFileInfoList'); 

回答

4

我想你可以通过改变onSelect回调日期选择器的解决这个问题。您可以更改

onSelect: function() { 
    $(this).keydown(); 
} 

onSelect: function() { 
    $(this).trigger('change'); 
} 

您可以使用也更复杂的结构,我在the answer或更多一点简单的形式发布来自here

+0

不知道为什么这个工作......但它确实。 – CaffGeek

+0

@CaffGeek:jqGrid使用'change'处理程序来更新稍后发送到服务器的内部数据结构(参见[here](https://github.com/tonytomov/jqGrid/blob/v4.4.4/js/)例如,grid.filter.js#L224-L227))。如果使用'$(this).keydown()',最后一个控件的更改可能会丢失,尤其是如果您不使用最后一个版本的jqGrid。 – Oleg