2013-02-13 64 views
0

我正在嘗試爲jqGrid實現ToolBar Search/Filtering。當我在任何一個過濾器中輸入一些文本並點擊輸入時,什麼都不會發生 - 不知道我在這裏做了什麼錯誤。任何幫助表示讚賞:jqGrid filterToolbar無法正常工作 - ASP.NET

jQuery("#list").jqGrid({ 
      datatype: 'json', 
      url: 'GetIncidents.ashx?view=MyIncidents', 
      height: "100%", 
      scrollOffset: 0, 
      jsonReader: { 
       root: "rows", 
       page: "page", 
       total: "total", 
       records: "records", 
       repeatitems: false, 
       cell: "cell", 
       id: "ID", 
       userdata: "userdata", 
       subgrid: { 
        root: "rows", 
        repeatitems: true, 
        cell: "cell" 
       } 
      }, 
      colNames: ['ID', 'Title', 'Assigned To', 'Status', 'Priority', 'Classification', 'Affected User', 'Support Group', 'Last Modified'], 
      colModel: [ 
        { name: 'ID', index: 'ID', width: 40, sorttype: 'int', firstsortorder: 'desc' }, 
        { name: 'Title', index: 'Title', width: 180 }, 
        { name: 'AssignedUser', index: 'AssignedUser', width: 100, align: 'center' }, 
        { name: 'Status', index: 'Status', width: 50, align: 'center' }, 
        { name: 'Priority', index: 'Priority', width: 50, align: 'center' }, 
        { name: 'Classification', index: 'Classification', width: 150, align: 'center' }, 
        { name: 'AffectedUser', index: 'AffectedUser', width: 100, align: 'center' }, 
        { name: 'TierQueue', index: 'TierQueue', width: 100, align: 'center' }, 
        { name: 'LastModified', index: 'LastModified', width: 120, align: 'center', formatter: 'date', formatoptions: { srcformat: 'Y-m-d H:i:s0', newformat: 'm/d/Y h:i A'}}], 
      pager: '#pager', 
      rowNum: 15, 
      width: 980,     
      sortname: 'ID', 
      sortorder: 'desc', 
      viewrecords: true, 
      autowidth: true, 
      gridview: true, 
      ignoreCase: true, 
      caption: 'All Open Incidents Assigned To Me', 
      onSelectRow: function (id) { window.location = 'ViewIncident.aspx?id=' + id; } 
     }); 

     jQuery("#list").jqGrid('filterToolbar', { stringResult: true, searchOnEnter: false, defaultSearch: "cn" }); 

回答

0

jqGrid的依賴於服務器的過濾功能上,如果你檢查你的外出行動後,你會看到額外的數據被添加到經過過濾的數據後。

因此,您的過濾將在服務器上完成,然後過濾數據集將被排序/分頁等,然後傳回給您的jqGrid。

在我看來,這是開始的地方:它會需要一點努力建立但是從那裏,你將有一個很好的基礎來處理動態過濾 ASP.NET MVC 2.0 Implementation of searching in jqgrid

從這個例子。如果你只是處理非常基本的過濾,你可能可以使用一些組件來破解一些東西,但過去的基本要求會讓它值得花時間在這個額外的選項上。

0

幾件事情首先嚐試添加的document.ready功能,讓你的瀏覽器加載發射了前柵格,然後添加loadonce:真實,

然後嘗試運行它,它應該工作!

下面是代碼

JQuery(document).ready(function(){ 
jQuery("#list").jqGrid({ 
     datatype: 'json', 
     url: 'GetIncidents.ashx?view=MyIncidents', 
     height: "100%", 
     scrollOffset: 0, 
     jsonReader: { 
      root: "rows", 
      page: "page", 
      total: "total", 
      records: "records", 
      repeatitems: false, 
      cell: "cell", 
      id: "ID", 
      userdata: "userdata", 
      subgrid: { 
       root: "rows", 
       repeatitems: true, 
       cell: "cell" 
      } 
     }, 
     colNames: ['ID', 'Title', 'Assigned To', 'Status', 'Priority', 'Classification', 'Affected User', 'Support Group', 'Last Modified'], 
     colModel: [ 
       { name: 'ID', index: 'ID', width: 40, sorttype: 'int', firstsortorder: 'desc' }, 
       { name: 'Title', index: 'Title', width: 180 }, 
       { name: 'AssignedUser', index: 'AssignedUser', width: 100, align: 'center' }, 
       { name: 'Status', index: 'Status', width: 50, align: 'center' }, 
       { name: 'Priority', index: 'Priority', width: 50, align: 'center' }, 
       { name: 'Classification', index: 'Classification', width: 150, align: 'center' }, 
       { name: 'AffectedUser', index: 'AffectedUser', width: 100, align: 'center' }, 
       { name: 'TierQueue', index: 'TierQueue', width: 100, align: 'center' }, 
       { name: 'LastModified', index: 'LastModified', width: 120, align: 'center', formatter: 'date', formatoptions: { srcformat: 'Y-m-d H:i:s0', newformat: 'm/d/Y h:i A'}}], 
     pager: '#pager', 
     rowNum: 15, 
     width: 980,     
     sortname: 'ID', 
     sortorder: 'desc', 
     viewrecords: true, 
     autowidth: true, 
     gridview: true, 
     ignoreCase: true, 
     loadonce:true, //**you need to add this** 
     caption: 'All Open Incidents Assigned To Me', 
     onSelectRow: function (id) { window.location = 'ViewIncident.aspx?id=' + id; } 
    }); 

    jQuery("#list").jqGrid('filterToolbar', { stringResult: true, searchOnEnter: false, defaultSearch: "cn" }); 

})